Solved

Exception

Posted on 2002-03-20
6
257 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
LAN or WAN ? 11 92
Delphi Yen format 3 35
Tvertscrollbox like a whatsapp layout delete messages 1 17
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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