Solved

Make a global exceptionhandle

Posted on 1998-09-09
4
174 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
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
bozo7 earned 200 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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