Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to enhance error messages Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
The address of the exception : an essential information 30-Sep-06
Delphi All Versions
User Rating
No Votes
# Votes
Sampy, Robert
Reference URL:
Robert Sampy
			The address of the exception : an essential information
The best way to display the address of the last exception is to customize the 
application's default exception handler : Application.OnException.

Delphi code starts here.
2   procedure TfmMain.FormCreate(Sender: TObject);
3   begin
4     Application.OnException := OnAppliException;
5     ...
6   end;
8   procedure TfmMain.OnAppliException(Sender: TObject; E: Exception);
9   begin
10    try
11      E.message := E.message + ' at address $' + IntToHex(Integer(ExceptAddr), 8);
12      Application.ShowException(E);
13    except
14      MessageDlg('Error in exceptions handler.', mtError, [mbOk], 0);
15    end;
16  end; 
18  function TfmMain.DoDivide(Up,Down : Integer) : Integer;
19  begin
20    Result := Up div Down;
21  end

Delphi code ends here.

In these few lines of code, the application first redirects its default exceptions 
handler towards OnAppliException procedure. This new handler displays the exception 
and its address.

Why is it important ?
Because the programer can find the line of code which raised the exception with the 
address of the exception. In our example, he has to
- launch Delphi and execute the application,
- open 'Execution error' option in Delphi's 'Search' menu,
- enter $00458833.
Then Delphi shows the line
  Result := Up Div Down;
The error line is located in the sources and the debugging task can really begin... 
Here, we have to modify DoDivide function by adding a test on Down parameter.

The address of the exception is so an important information that it should always 
be displayed in error messages ! Don't hesitate to add these few lines of code into 
your applications : it will already be of a great help for your debugging sessions.

Robert Sampy

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC