Solved

Make a global exceptionhandle

Posted on 1998-09-09
4
177 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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