Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Exceptions    [ Add a report in this area ]  
Report #:  2963   Status: Closed
Re-raising catched exception object causes access violation
Project:  Delphi Build #:  6.240
Version:    6.0 Submitted By:   Dmitry Surkov
Report Type:  Crash / Data loss / Total failure Date Reported:  11/21/2002 3:14:50 AM
Severity:    Critical / Show Stopper Last Updated: 5/2/2003 12:58:35 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Test Case Error (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
1.00 out of 5
Total Votes: None
Description
This program code produces access violation.

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    raise Exception.Create('Test exception');
  except
    on E: Exception do
      raise E;   // E is auto-deleted, so raise produces AccessViolation
  end;
end;

If you would replace [raise E;] with simply [raise;], then you would get no problems. So, the follwing code runs OK:

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    raise Exception.Create('Test exception');
  except
    on E: Exception do
      raise;   // E is re-raised without deletion.
  end;
end;

The question is: whether this is compiler feature (rather stupid), or a bug? Semantically there should be no differences between two raises.

I'm sure that the bug (or feature :-) exists in D7.
Steps to Reproduce:
procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    raise Exception.Create('Test exception');
  except
    on E: Exception do
      raise E;   // E is auto-deleted, so raise produces AccessViolation
  end;
end;
Workarounds
None
Attachment
None
Comments

Stefan Hoffmeister at 11/21/2002 10:23:47 AM -
Please ask questions in the newsgroups. Quality Central is a database of reports covering, for instance, defects and requests for enhancements.

Your use of "raise E" as demonstrated in your code is faulty.

Dmitry Surkov at 11/22/2002 9:27:43 AM -
Marking such topics as Closed may result in missed conceptual weaknesses. I hope you've reported this to language architects.

Stefan Hoffmeister at 11/23/2002 2:52:44 PM -
>Marking such topics as Closed may result in missed conceptual weaknesses

You complained about a defect and provided an example. Your example is faulty and does not describe a defect, because what you describe works (well, it doesn't work) the way it is documented.

Of course you can disagree with the design, and of course you can ask for changes to the design - but this is exactly what your report did *not* do.

For the above reasons, this report will remain closed as a Test Case Error.

Please submit a new report if you want the design changed.

Stefan Hoffmeister at 11/25/2002 6:03:20 AM -
An enhancement request has been entered.

Dmitry Surkov at 11/22/2002 9:20:29 AM -
Take it as a request for enhancement. I understood that the demonstrated code is faulty.

The documentation says that Delphi handles deletion of the exception object itself. From the common sense re-raising of the catched exception object should not destroy it.

Stefan Hoffmeister at 11/22/2002 11:12:46 AM -
>Take it as a request for enhancement.

The report has been closed already. I have reverted the changes you made to the report to what it was.

If you wish to make a feature request, please enter a separate report - and do not say "I'm sure that the bug ... exists in D7" while giving it a show-stopper rating.

Server Response from: ETNACODE01