How to save all the exceptions of type "EAccessViolation"?

delphi package - automated exception handling
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

How to save all the exceptions of type "EAccessViolation"?

Post by car_hack89 »

Hello,

Is it possible to save all the exceptions of type "EAccessViolation" in the bug report, even if the code has try-except ?. As in the following example:

Code: Select all

procedure FuncX ();
var strList: TStringList;
begin
    try
        strList.Clear; // Here occurs Access Violation
        // ..
    except on E: Exception do
       ShowMessage (E.Message);
    end;
end;
The goal is to save the bug report automatically, so I do not have to manually put it in all try-except of my application.

Thanks in advance.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

You can use RegisterHiddenExceptionHandler(). If you set "handled := false" in such a handler, madExcept will start report such "hidden" (handled by a try..except block) exceptions, too.
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

Just what I needed.

Thank you!
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

Hello,

The proc. RegisterHiddenExceptionHandler(), it was useful, but it impacted the performance of my application. I have the following sample code:

Code: Select all

iCount: = 0;
While iCount <= 1000 do begin
    try
       raise Exception.Create('My test exception');
    except on E: Exception do
    end;
    Inc (iCount);
end;
My result of the previous example is the following:

1) Using the proc. RegisterHiddenExceptionHandler(): 2 minutes, and on some computers it may take 5 or 10 minutes

2) Without the use of proc. RegisterHiddenExceptionHandler(): 0.056 seconds.

Any recommendations with the madExcept configuration?

I tried with TExceptEvent and TExceptEventOO, as well as I tried with the three TSyncType (stDontSync, stTrySyncCallOnSuccess, stTrySyncCallAlways).

Thanks in advance.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

Well, analyzing exceptions costs time, and using HiddenExceptionHandler with "handled := false" means that madExcept is going to analyze every exception is full detail.

What you could do is try to figure out in your HiddenExceptionHandler if the exception is of interest to you or not, by looking at the "exceptIntf" properties. Do not use "exceptIntf.BugReport", though, because that will force madExcept to calculate the full bug report before returning to you.

Hope that helps?
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

In my HiddenExceptionHandler I evaluate the exceptions of type "Exception". I also tried, removing the code from my HiddenExceptionHandler, and the performance problem persists.

Any other recommendation, to intercept the exceptions that have try-except?
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

Originally, you only asked for EAccessViolation. So why don't you do something like:

Code: Select all

handled := (exceptIntf.ExceptClass = nil) or (not (exceptIntf.ExceptClass is EAccessViolation));
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

The code of my HiddenExceptionHandler is the following:

Code: Select all

procedure MyHiddenExceptionHandler (const exceptIntf: IMEException; var handled: Boolean);
begin
    //I removed my code temporarily,
    //and the performance problem persists.
end;
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

What about my suggestion? Have you tried it?
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

Yes, I already tried it, and the result is the same. Based on my tests, I think the performance problem is before executing my HiddenExceptionHandler, maybe in the function madExcept.FireHandlers() or madExcept.ReceiveHandleException().
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

Ok, found a recently introduced bug which slowed this down a lot. Here's a test build which should speed this up noticeably:

http://madshi.net/madCollectionBeta.exe

It'll still be slower than not using the HiddenExceptionHandler stuff, of course (there's no free lunch, obviously), but I hope it will be acceptable now?
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

First of all, I appreciate it. Improved performance by 65%.

Can I use the BETA release that you sent me in my productive applications?

**Even with the cost of using HiddenExceptionHandler, it would be very good if it were faster, I will be aware of any subsequent performance improvement.

Thank you very much.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: How to save all the exceptions of type "EAccessViolation

Post by madshi »

Strange, for me the performance improvement was much much more than 65%. You did use stDontSync?
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

Let me check it, and perform more tests.
car_hack89
Posts: 21
Joined: Tue Mar 27, 2018 1:30 am

Re: How to save all the exceptions of type "EAccessViolation

Post by car_hack89 »

Hello, after several tests, the result was the following:

1.- The time with HiddenExceptionHandler, is variable depending on the location of the source code, for example:

If the code of the "While" with 1,000 iterations is in the FormCreate of my TForm, it takes 25 seconds.

But if I move it to a global/static procedure within the same unit, it now takes 7 seconds.

2.- During the tests, initially the times were 40 seconds, then 36 and finally 25 seconds.

3.- The time with HiddenExceptionHandler, of an application of x32 bits, and of one of x64 bits is 10 seconds of difference, that is, it takes 10 seconds more.

4.- The time, also increases if within the try-except is added more code apart from the raise Exception, for example creation of TDataSet's, etc.

Thanks in advance.
Post Reply