Is this
try
DoSomethingThatMightThrowAnException;
except
on E : ESyntaxError do
begin
if (E.ErrorCode = errMissingBracket) then
HandleError
else
raise;
end;
end;
slower than this?
try
DoSomethingThatMightThrowAnException;
except
on E : EMissingBracketSyntaxError do
begin
HandleError;
end;
end;
What’s the difference to be expected? Does it matter? Note that this could happen several times through the call stack.
I’ve had a quick look at the assembler the compiler spews out for above code snippets. Turns out that the bytes right after
jmp @HandleOnExeptioncontain data such as the exception class pointers you use in theonclauses (if any).I’m not that well versed in assembler to know exactly what’s going on, but enough to understand what is roughly going on and come to this conclusion:
I suspect System.pas’ HandleOnException does a
call @IsClassalready, and passes the exception on if no suitable handler is found, so if you useon e:Exceptionand re-raise, this will add a little code and make two calls extra:call @RaiseAgain(in cases the exception gets re-raised)So, there’s a difference. A minor one, but still, it’s there.