Watch, Follow, &
Connect with Us

Please visit our new home

Public Report
Report From: Delphi-BCB/Compiler/Delphi/Exceptions    [ Add a report in this area ]  
Report #:  104611   Status: Closed
Exception destroyed more than once
Project:  Delphi Build #:  16.0.4429.46931
Version:    16.4 Submitted By:   Tvr Tvr
Report Type:  Issue Date Reported:  4/4/2012 2:57:05 AM
Severity:    Extreme corner case Last Updated: 4/15/2014 6:48:11 PM
Platform:    All platforms Internal Tracking #:   27412
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Exception is destroyed more than once, when in lifetime of exception is an dll unloaded and both dll and application are compiled with runtime packages.
Steps to Reproduce:
1. Open attached 'DummyLib.dproj'. It is empty project as below.
library DummyLib;
{$R *.res}
2. Build DummyLib.dll library with runtime packages.
3. Open attached 'TestExcpetion.dproj'
4. Build TestException.exe with runtime packages.
unit fTestException;
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

  ETestException = class(Exception)
    destructor Destroy; override;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);

  Form1: TForm1;
{$R *.dfm}
{ ETestException }

destructor ETestException.Destroy;
  //exception is destroyed 2  times - first time during library unload,
  //second time on the except handler end
  OutputDebugString('ETestException destroying');

procedure TForm1.Button1Click(Sender: TObject);
  mHandle: HMODULE;
    mHandle := LoadLibrary('DummyLib.dll');
      raise ETestException.Create('just for demonstration');
    OutputDebugString('except handler');


In test project wrote try except block, inside this block put code, which load dummy library followed by try finally block. Inside this block put raise of some exception and into finally part put free dummy library.

When running it and clicking button, then raised exception is freed more then one time. First time during dummy library freeing, second time on end of except handler.

This occur only when both application are compiled with runtime packages.

I has join an code example for demonstration.

Tomohiro Takahashi at 4/5/2012 12:07:17 AM -
>   //exception is destroyed 2  times - first time during library unload,
>  //second time on the except handler end
>  OutputDebugString('ETestException destroying');
I built and run attached projects, but I can not reproduce your issue.

My steps are as below.
1. open  'DummyLib.dproj' and build it
2. open 'TestException.dproj'.
3. remove invalid(3rd-party) packages from project option, because it causes compile errors in my environemnt
3. build 'TestException.dproj'
4. add breakpoint onto 'OutputDebugString('ETestException destroying');' line
4. run TestException.exe
5. click Button
6. stop at the breakpoint once properly
7. click Button again
8. stop at the breakpoint once properly again

Uwe Schuster at 4/8/2012 2:37:30 AM -
I can repeat it, but the behavior could be as designed and I'll get that checked.

It repeats only when DummyLib.dll and TestException.exe are both linked against runtime packages. A difference could make the first step and that means instead of your

> 1. open  'DummyLib.dproj' and build it

my first steps were similar to your second till fourth step and were

1.1. open DummyLib.dproj
1.2. remove packages from the Runtime packages list that are not installed on my system
1.3. build DummyLib.dproj

Tomohiro Takahashi at 4/8/2012 5:29:27 PM -
Could you please re-attach sample project, which does not refer to 3rd-party packages, in order to reproduce your issue more easily, since we can not build your project due to the pakcage?

Tvr Tvr at 4/11/2012 8:36:47 AM -
Sorry, I forgot packages we have used are included. I leaved in both projects only rtl and vcl packages and simulate same error.

Tvr Tvr at 4/11/2012 8:42:52 AM -
And probably I am blind but I see no way how to attach other attachment

Tomohiro Takahashi at 4/19/2012 5:46:34 PM -
This report was opened with valid Internal Tracking Number.

Server Response from: ETNACODE01