try
...
try
...
...
... (something wrong here)
...
finally
...
end;
except
...
end;
if (something wrong here) raises an exception, yes, execution will pass
first through the finally, then the except, skipping anything not enclosed
in those blocks. If the exception is handled in the except block, execution
will resume after the exception block, otherwise it will go to the next
exception block.
Yes it will, though I think the preferred way is
try
...
try
...
...
... (something wrong here)
...
except
...
end;
finally
...
end;
Nick Hodges -- TeamB
Lemanix Corporation
How to ask questions of techies --
http://www.tuxedo.org/~esr/faqs/smart-questions.html
try
except
on e:exception do
messagebox(0,pchar(e.message),'Warning',MB_OK+MB_ICONINFORMATION);
end;
"Nick Hodges (TeamB)" <nickh...@yahoo.com> wrote in message
news:kfrm1v4hi57f3nh3v...@4ax.com...
> on e:exception do
> messagebox(0,pchar(e.message),'Warning',MB_OK+MB_ICONINFORMATION);
That's actually redundant, because that is what the default mechanism
will do anyway.
>It only showed the finally message but not exception message.
That is because the optimizer removes the code -- try to put a
breakpoint on
i := 1 div i;
Turn optimizations off, or add a label, and put this line at the end
of your snippet
Label1.Caption := IntToStr(i);
That will keep the variable i from being optimized away
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
i:=0;
try
try
i := 1 div i;
finally
showmessage('after division');
end;
except
showmessage('exception');
end;
Label1.Caption := IntToStr(i);
end;
var
i: integer;
begin
i:=0;
try
try
i := 1 div i;
finally
showmessage('after division');
end;
except
showmessage('exception');
end;
end;
It only showed the finally message but not exception message.
>Yes, so should I turn the Optimisation On or Off when distribute my
>application ?
You probably should leave optimizations on all the time, unless there
is some particular debugging situation that you can't do any other
way.
I leave optimizations on 99.9999999% of the time. Generally, if you
feel the need to turn off optimizations, that is a strong indicator
that there is something wrong with your code.
"Nick Hodges (TeamB)" <nickh...@yahoo.com> wrote in message
news:8hcp1vcl230172q0e...@4ax.com...