Solved

Exception

Posted on 2002-03-20
6
261 Views
Last Modified: 2010-04-05
hai

the problem is that i want to capture an exception message when it occurs and store it in a log file. Suppose if an EDBEngineError occurs i want to capture the exception as well as the related system thrown message and store it in a log file.

thank u in advance...
0
Comment
Question by:shyampaliyath
[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
6 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6884679
Get the Jedi Code Library from http://delphi-jedi.org/CODELIBJCL (new release 1.2 due in the next days).
JclDebug is what you need even that only catching and logging the exceptions is almost too easy for the unit :-)
0
 
LVL 7

Expert Comment

by:Motaz
ID: 6884870
Suppose that you have function called AddLog that add string line to Log file:

try
  // put your database manipulation code here:
except
  on e: exception do
    AddLog(E.Message);
end;
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6884979
Delphi 5 introduced a simpler way of achieving this. Use the TApplicationEvents component on the Additional tab:

In the OnException event, put the passed exception's message in your log file, then call Raise to show the exception to the user.

If you are using a version of Delphi less than D5, then you'll have to write your own procedure then assign it to the Application's OnException event in your main form's OnCreate, e.g.

procedure TForm1.FormCreate(Sender: TObject);
begin
   Application.OnException := MyExceptionHandlingProcedure;
end;

J.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
VSF earned 200 total points
ID: 6888352
Use a TTable Component with this settings:
DatabaseName: "c:"
TableName: "LogError.txt"
TableType: "ttASCII"

Add the following code:
procedure TForm1.FormCreate(Sender: TObject);
begin
  if not fileExists('C:\LogError.txt') then
    table1.createtable;
  table1.open;
  application.onexception:=LogError;
end;

procedure TForm1.LogError (Sender: TObject; E: Exception);
var msg: string;
begin
  try
    table1.append;
    table1.fieldbyname('DataHora').asString:=FormatDateTime('dd/mm/yyyy hh:mm:ss',now);
    table1.fieldbyname('Form').asString:=screen.activeform.name;
    table1.fieldbyname('Control').asString:=screen.activecontrol.name;
    table1.fieldbyname('Mensage').asString:=e.message;
    table1.post;
  except
  end;
  msg:=e.message+#10+#10;
  msg:=msg+'Form: '+screen.activeform.name+#10;
  msg:=msg+'Control: '+screen.activecontrol.name;
  MessageDlg(msg,mtError,[mbOK],0);
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6896735
You might also want to look at my exception handling package:

http://help.madshi.net/Data/madExcept.htm

Regards, Madshi.
0
 
LVL 3

Expert Comment

by:VSF
ID: 6898925
Glad to help!

Please show your support by entering this sites:
www.victory.hpg.com.br
www.enge.cjb.net
www.boatoda.hpg.com.br

VSF
victory@e-net.com.br
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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