Hah. I do use exceptions in my code, but I somehow overlooked them. This is indeed the best thing to do.
Sometimes, I don't want to use exceptions, because I want to have "silent failure". That would be something like:
Code:
Texture := Manager.FindTexture('mytexture');
if not assigned(Texture) then
begin
//Respond accordingly.
end;
So FindTexture will return NIL when nothing is found. This can be handy when you want to write a function like Manager.IsTextureLoaded(). You will just do the following:
Code:
function TManager.HasTexture(aName: String): Boolean;
begin
Result := Assigned( FindTexture(aName) );
end;
Which is IMHO alot neater than:
Code:
function TManager.HasTexture(aName: String): Boolean;
begin
Result := True;
try
FindTexture(aName);
finally
on E: ETextureException do
Result := false;
end;
end;
Bookmarks