How to just log an exception?

delphi package - automated exception handling
Post Reply
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

How to just log an exception?

Post by santiago »

Hi there,

we are evaluating madExcept. Our app is still using Exceptional Magic.

So far I'm very impressed with madExcept.

I see the HandleException function has a parameter named: showReport of type TPString.
What is that for? It is not described in the docs.

Thanks!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to just log an exception?

Post by madshi »

It seems your question in the caption of this thread is different to the question in the text?

The "showReport" parameter is mostly used internally, for ISAPI/HTTP/Web exception handling. It returns the full bug report for the exception.

About "how to just log an exception": Can you tell me a few more details about what you want/need exactly?
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

Thanks for the quick reply!!!

Yes, when I started the post I was trying to just log an exception. But then I figured it out (or at least thought so :-) ).

In ExceptionalMagic you could call a method that would just add the exception to the log file.

This is useful if you have a try except block. In some cases we don't want the exception box to be shown but would like the exception to be added to the log file nevertheless.

I did this:

procedure LogException;
var
BugReport: string;
begin
BugReport := CreateBugReport(etNormal);
AutoSaveBugReport (BugReport);
end;

At first it seemed as it worked, but taking a closer look I realize that the registered exception handlers are NOT called. So the output is incomplete (I add some additional header values).

How can I have the exception just added to the log file, without the exception box being shown? (All registered exception handlers need to be called).

Thanks!

sb
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to just log an exception?

Post by madshi »

Do you need those try..except blocks? One way would be to remove the try..except blocks and let madExcept handle the exception. (Or simply call "madExcept.HandleException()" in the try..except block, if you don't want to remove it for some reason). In that case madExcept will fully handle the exception, and by default the exception box will be shown.

Your handlers have control over whether the exception box is actually shown or not. So your handlers can check certain information fields, e.g. "exceptIntf.ExceptClass" or "exceptIntf.ExceptObject". If you can figure out which of those exceptions should show an exception box from inside your handler, you can set "exceptIntf.ShowSetting := ssNothing" to hide the exception box.
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

Thanks for the addiotional info.

Unfortunately those try except blocks need to stay.

Is it possible to have CreateBugReport call all registered exception handlers?
That would be best way to achieve what we need.

Thanks again!
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

I got it to work by passing a special dummy object as RelatedObject to Handle Exception

Code: Select all

HandleException(etNormal, nil, nil, True, 0, 0, nil, esManual, FlagObject, 0);
In my handler:

Code: Select all

  if exceptIntf.RelatedObject = FlagObject then
    exceptIntf.ShowSetting := ssNothing;
If I understand correctly 'RelatedObject' can be set to anything, it can be thought of as a pass-through value.

Please do let me know if this approach is not correct.

Thanks!
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

The approach I described above works. But there is one small detail (which should be simple to solve, I hope) that needs to be addressed.

If I just raise an exception (without try except) the madExcept box shows up almost instantly. It is very fast.

However if I use the approach outlined above, which consists of calling HandleException (with a special RelatedObject) first the "Please Wait" dialog shows up with the progress bar. That stays up for ca. 3 seconds and then disappears.
No exception box is shown, and the exception is added to the log file -> this is exactely what I need.

The question is why does calling HandleException result in the 'Please wait' dialog being shown? Why does it take soooo long? If the exception is handled directly by madExcept the box shows up instantly.
I guess it must be some settings. Just have not been able to figure it out so far...

Thanks!!
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

I was reviewing some older posts on this forum and ran into this one:

madExcept is busy for a long time after crash
viewtopic.php?f=4&t=27973

In there madschi asks:

"
2) Are you using self written DLLs which are compiled with madExcept?
"

This is the case for me.

We have OurApp.exe which depends on LibA.bpl

In LibA I have made use of madExcept.

Maybe this helps?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to just log an exception?

Post by madshi »

The progress bar behaviour is explained here:

http://help.madshi.net/madExceptUnit.ht ... .BugReport

Of course you can simply disable the "show please wait box" option in the madExcept settings. But the delay will still be there, just no progress window.
santiago
Posts: 73
Joined: Thu May 05, 2016 6:01 pm

Re: How to just log an exception?

Post by santiago »

madshi,

thanks for all your help!

I am sorry, but I still do not quite understand why the delay happens when I manually call HandleException inside the except block.

If I remove the try except block and just let madExcept handle the exception. The exception box appears instantly and already contains all the info required for the bug report.
This means that the bug report data can be computed very fast.

However if I instead place a try except and call HandleException with the except the delay happens (several seconds). I know that I can hide the 'please wait' box, however I want to get rid of the delay, because as stated above all the info for the bug report can be generated very fast.

In my test case it is the same exception being thrown in both cases. The only difference being the try except block (and the delay ...).

Thanks again!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to just log an exception?

Post by madshi »

Have you read the link I posted? Here's the key extract:
you first need to understand, that madExcept calculates the bug report in a background thread, while already calling your registered exception handlers at the same time. As long as you behave nicely, this logic works quite fine and results in that the exception box can be shown without delay, although the calculation of the full bug report might not be fully done yet.
The calculation of the callstacks can take quite a bit of time. The exception box is already shown before the callstacks are fully calculated.

Simply hide the progress alert, that's really all you need to do.
Post Reply