Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make a global exceptionhandle

Posted on 1998-09-09
4
Medium Priority
?
182 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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