Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
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
Category
N/A
Language
Delphi All Versions
Views
54
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
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.
1   
2   procedure TfmMain.FormCreate(Sender: TObject);
3   begin
4     Application.OnException := OnAppliException;
5     ...
6   end;
7   
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; 
17  
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

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC