Re: Try Finally...
From: Duncan McNiven (duncan_at_mcniven.net)
Date: 10/25/04
- Next message: Sven Pran: "Re: LPT port, anyone ?"
- Previous message: Marco van de Voort: "Re: Try Finally..."
- In reply to:(deleted message) L D Blake: "Re: Try Finally..."
- Next in thread: Martin Harvey (Demon account): "Re: Try Finally..."
- Reply: Martin Harvey (Demon account): "Re: Try Finally..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 25 Oct 2004 14:45:10 +0100
On Mon, 25 Oct 2004 08:23:21 -0400, L D Blake <not@any.adr> wrote:
>
> Program test;
> var
> x,y : longint;
>
> procedure doit(z:longint);
> begin
> try
> y := 100;
> x := y div z;
> finally
> writeln('in the finally block now');
> end;
> end;
>
> begin
> doit(0);
> writeln('if you''re right you will see this');
> end;
>
>
>The program will terminate in the finally block
No it won't. It will continue at the next outer try .. finally or try
... except construct. Since you haven't provided one, execution goes to
the application's default exception handler, and terminates there.
>and you will never see the
>final writeln "if you're right you will see this');
Correct, because you have not provided a try ... except construct to
handle the exception, or a try ... finally construct to ensure the final
writeln is executed despite the exception.
>There are two conditions under which finally is entered...
>
> 1) Normally... the code is executed and the program continues.
Yes
> 2) Exception... the code is executed and the program terminates.
Only because you have provided no code to handle the exception. It
doesn't have to be like that; this behaviour is your choice. If you want
it to do something different, you have to write some code.
Test this:
program Test;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
x,y : longint;
procedure doit(z:longint);
begin
try
y := 100;
x := y div z;
finally
writeln('in the finally block now');
end;
end;
begin
try
doit(0);
except
on EDivByZero do begin
writeln('How can you see this if FINALLY terminated to app?');
readln;
end;
end;
end.
-- Duncan
- Next message: Sven Pran: "Re: LPT port, anyone ?"
- Previous message: Marco van de Voort: "Re: Try Finally..."
- In reply to:(deleted message) L D Blake: "Re: Try Finally..."
- Next in thread: Martin Harvey (Demon account): "Re: Try Finally..."
- Reply: Martin Harvey (Demon account): "Re: Try Finally..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|