Solved

Make a global exceptionhandle

Posted on 1998-09-09
4
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now