How to use MadExcept in handled exceptions?

delphi package - automated exception handling
Post Reply
Goran
Posts: 5
Joined: Mon Sep 20, 2004 12:40 pm

How to use MadExcept in handled exceptions?

Post by Goran »

Hi

I use try .. except blocks for database app , and in except block I use rollback if anything goes wrong. How can I use Madexcept to silently create bugreport after I made rollback?

Goran
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You can call "CreateBugReport(etNormal)" to get a full bug report as a string. However, that only works inside of a try..except block. Does that help?
Goran
Posts: 5
Joined: Mon Sep 20, 2004 12:40 pm

Post by Goran »

That is exactly what I wanted.
Great job.
Goran
Posts: 5
Joined: Mon Sep 20, 2004 12:40 pm

Post by Goran »

Just one more question.

Just made my function rollbackerror() in mylibunit like :

function rollbackerror () : boolean ;
var
mybugreport : string ;
f : textfile ;
begin
mybugreport := CreateBugReport(etNormal);
AssignFile(f, 'bugreport.txt');
Append(f);
Writeln(f, mybugreport);
Flush(f); { ensures that the text was actually written to file }
CloseFile(f);
end;

and in units where I need rollback control just do this :
try
.. do something bla bla ...
DtaMod.Dbase.Commit;
except
rollbackerror() ; // my errorlogging function
DtaMod.Dbase.Rollback;
end;

Is this good way to go, or I have to look for something ?
Thanx.

Goran
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, you can do that. However, if multiple threads will crash at the same time, not all threads will be able to access the log file at the same time.
Post Reply