Solved

Exception

Posted on 2002-03-20
6
255 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

12 Experts available now in Live!

Get 1:1 Help Now