Solved

Exception

Posted on 2002-03-20
6
256 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. Spend 30 short minutes with us to learn:   • Key questions to ask when considering a partnership to accelerate your business into the cloud • Pitfalls and mistakes other partners…

911 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

20 Experts available now in Live!

Get 1:1 Help Now