Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/RTL Exceptions    [ Add a report in this area ]  
Report #:  51427   Status: Closed
Calling Halt in 'except' or 'finally' forcibly displays the exception message, and causes process to return wrong exit code
Project:  Delphi Build #:  11.0.2902.10471
Version:    11.2 Submitted By:   Jordan Russell
Report Type:  Basic functionality failure Date Reported:  8/31/2007 8:37:56 PM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   257154
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3503.23917
Duplicate of:  None
Voting and Rating
Overall Rating: (3 Total Ratings)
5.00 out of 5
Total Votes: 16
Description
This is a new problem introduced in Delphi 2007 (and still repro with the Dec2007 update installed):

If Halt is called inside an 'except' or 'finally' block, the current exception's message is forcibly displayed on the screen, and the process returns with an exit code of 1 instead of the exit code specified in the Halt call.

The cause appears to be these lines in SysUtils' DoneException procedure, which are new to Delphi 2007:

  if ExceptObject <> nil then
    ExceptHandler(ExceptObject, ExceptAddr);

I assume the intention there is to ensure that any new exceptions raised during termination are brought to the attention of the user.

In my case, however (see the example code), the exception was raised before termination commenced. DoneException should ignore such pre-existing exceptions. And it certainly should not be changing my exit code from 5 to 1.
Steps to Reproduce:
Run this code:

program Project1;

uses
  Windows, SysUtils;

begin
  try
    raise Exception.Create('xxx');
  except
    Halt(5);
  end;
end.


Expected results (what happened in Delphi 2.0 through 2006):

1. The process should return with an exit code of 5.


Actual results on Delphi 2007:

1. A message box is displayed:

---------------------------
Application Error
---------------------------
Exception Exception in module Project1.exe at 00055753.

xxx.
---------------------------
OK  
---------------------------

2. The process returns with an exit code of 1, not 5.
Workarounds
None
Attachment
None
Comments

Marcio Vieira at 11/13/2008 12:00:11 PM -
I am using Delphi 2007 11.0.2902.10471 on a Windows XP SP3 machine and the problem above is still happening.  

I have a console application with a try..except statement and the command Halt(1); within the except block.  When I run the program in such a way that it has to execute the except block, the following is printed on the output console:

Exception Exception in module program.exe at 000A6192.

Tomohiro Takahashi at 11/14/2008 9:35:18 PM -
Hi,
AFAIK, there is no update for Delphi 2007, 2006 ... sigh...

Alexey Beloborodov at 3/30/2009 9:18:22 PM -
... And it's very good: the 'fix' had introduced the memory leak.

See 72439 and

From: "Andre kaufmann"
Subject: Memory Leak on Thread Creation ?
Date: Mon, 23 Mar 2009
Message-ID: <95778@forums.codegear.com>

Server Response from: ETNACODE01