?
Solved

Make a global exceptionhandle

Posted on 1998-09-09
4
Medium Priority
?
179 Views
Last Modified: 2010-04-06
I would like some help to write a global exceptionhandle for my program, so all my programs exceptions can be logged in a file.

Thank you

LPD
0
Comment
Question by:lpd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
bozo7 earned 400 total points
ID: 1339202
Declare a procedure in your main form like so

Procedure AppException(Sender: TObject; E:Exception);

The code for this procedure would look something like this

Procedure TForm_Main.AppException(Sender: TObject; E: Exception);
var sEDate,sETime : String;
    sScreen, sControl,sEClass: string;
    myfilehandle: integer;
    F: TextFile;
begin
 try
     sEDate := datetostr(Date);//Records Date
     sETime := timetostr(Time);//Time of Error
     sScreen := screen.activeform.name;//Active Form
     sControl := screen.activecontrol.name;//Active Control
     sEClass := E.Classname;//Error Class

     assignfile(F,'c:\ErrorFile.txt');
     append(F);
     writeln(f,sEDate,' ',sETime,'',sScreen,'',sControl,         '',sEClass,' ',E.Message);
     closefile(f);

     messagedlg(E.Message,mtWarning,[mbok],0);//Shows user error
 except
       begin
            MYFileHandle := FileCreate('c:\fooderor.txt');
            fileclose(myfilehandle);
       end;

 end;//try-except
end;

Then in your Oncreate of the main form add this line of code

 pplication.OnException := AppException;//

Tells to use AppException Procedure

Let me know if this doesn't work. It has worked for me in 4 different apps now. Some i use a table this one i use a text file to hold all the errors.

bozo
ross@stiix.com
0
 
LVL 1

Expert Comment

by:bozo7
ID: 1339203
change line of code at the
MYFileHandle := FileCreate('c:\fooderor.txt');
to
MYFileHandle := FileCreate('c:\ErrorFile.txt');
you can substitute errorfile for whatever you want to call you file

bozo
0
 
LVL 1

Expert Comment

by:Zonnald
ID: 1339204
lpd,

I agree with the answer ( I found out trying to make an error handler for one form - which gets called from many others)

I am wondering to this day how you would make a local to form error handler - do I require a new question or is it easy in the context of this one??

Cheers

Zonnald


0
 
LVL 1

Expert Comment

by:bozo7
ID: 1339205
I am pretty sure that the application is the only object that has the onexception event. So I think that you could only use the exception handler globally.
bozo
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question