Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-09

Halt() bypassed try..finally block

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Is that correct behavior? When calling Halt() somewhere inside a try..finally block, it _doesn't_ execute the finally code.

In fpGUI I used Halt() to terminate the event loop and exit a application. I then noticed that NO cleanup code gets executed after that call. Not objects get freed via destructors etc... Since I noticed this, I implemented a more graceful termination process, but Halt() is really harsh! :-)

Regards,
- Graeme -

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Hi, Is that correct behavior? When calling Halt() somewhere inside a try..finally block, it _doesn't_ execute the finally code.

This is by design.

Halt finalizes the units and then exits.

Michael.

Reply by email

Matt Emson
to Michael Van Canneyt
Michael Van Canneyt wrote 12 lines
On Thu, 13 Sep 2007, Graeme Geldenhuys wrote: > Hi, > > Is that correct behavior? When calling Halt() somewhere inside a > try..finally block, it _doesn't_ execute the finally code. > This is by design. Halt finalizes the units and then exits.

Yeah, I always used to use something like:

var
  haltApp: boolean;
begin
haltApp := false;
try
  //some code that does something
  if (some_condition) then
  begin
    haltApp := true;
    exit;
  end;
  //some other code
finally
  //cleanup code
  if (haltApp) then Halt(halt_condition_code); // one could argue this
should be outside of the finally,
                                                                     //
but if it were it would not always be executed as
                                                                     //
desired - especially if an exception was raised.
end;

Reply by email