Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

try..except

0 views
Skip to first unread message

Alan

unread,
Jan 7, 2003, 6:07:33 PM1/7/03
to
With the except be carried out ?

try
...
try
...
...
... (something wrong here)
...
finally
...
end;
except
...
end;

David Knaack

unread,
Jan 7, 2003, 6:30:34 PM1/7/03
to
"Alan" <alan...@yahoo.com.au> wrote in message
news:3e1b...@newsgroups.borland.com...

> With the except be carried out ?
>
> 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.


Nick Hodges (TeamB)

unread,
Jan 7, 2003, 7:17:40 PM1/7/03
to
On Wed, 8 Jan 2003 10:07:33 +1100, "Alan" <alan...@yahoo.com.au>
wrote:

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

Tony Caduto

unread,
Jan 8, 2003, 8:32:33 AM1/8/03
to
And maybe add a on e:exception do in the except if needed.

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...

Nick Hodges (TeamB)

unread,
Jan 8, 2003, 12:48:33 PM1/8/03
to
On Wed, 8 Jan 2003 07:32:33 -0600, "Tony Caduto"
<aca...@amsoftwaredesign.com> wrote:

> 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.

Nick Hodges (TeamB)

unread,
Jan 8, 2003, 6:22:01 PM1/8/03
to
On Thu, 9 Jan 2003 10:13:55 +1100, "Alan" <alan...@yahoo.com.au>
wrote:

>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;

Alan

unread,
Jan 8, 2003, 6:13:55 PM1/8/03
to
I tried the following button click event:

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.

Nick Hodges (TeamB)

unread,
Jan 8, 2003, 6:52:36 PM1/8/03
to
On Thu, 9 Jan 2003 10:48:28 +1100, "Alan" <alan...@yahoo.com.au>
wrote:

>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.

Alan

unread,
Jan 8, 2003, 6:48:28 PM1/8/03
to
Yes, so should I turn the Optimisation On or Off when distribute my
application ?

"Nick Hodges (TeamB)" <nickh...@yahoo.com> wrote in message
news:8hcp1vcl230172q0e...@4ax.com...

0 new messages