Solved

Exception

Posted on 2002-03-20
6
260 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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