Page 1 of 1

Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 10:06 am
by christian.aymon
Hello,

How to configure madExcept so that it reports (i.e. generate a bug report) ONLY for certain exception classes, for example EAccessViolation.

Thank you.

Christian Aymon

Re: Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 12:08 pm
by madshi
What do you want to happen for other exception classes?

Probably you can configure everything to your liking here:

http://help.madshi.net/madExceptSettings3.htm

Re: Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 2:17 pm
by christian.aymon
In fact, we use many exception classes in our code to detect special conditions. The exceptions are handled in an OnException handler. Sometimes the handling just displays a message to the user.

In our code, we heavily use the exceptions mechanism and they don't indicate bugs. We would like to be able to list the exception classes for which madexcept should create a report, there are not that many. From your website, it seems that you consider almost all exceptions as ''errors'' and you provide a mechanism to filter ''out'' some exception classes. We have exactly the opposite situation: most exceptions are just part of the ''normal'' logic of the application and we just need a mechanism to filter ''in'' just a few cases that indeed reflect a real problem (for example AccessViolation), and where we need the information provided by madExept

We already had an exchange on this many years ago, in one of the ''borland'' forum and you gave a solutions, but I could not find the thread anymore. There are still some traces of MadExept in our code but it is difficult to understand what is going on:

In the ''main'' form we have the following maxexcept related code:

in the use clause:

Code: Select all

{$IFDEF USE_MADEXCEPT}
  ,MadExcept
{$ENDIF}
in the private section of the form:

Code: Select all

    // handler used when MadExcept is active
    procedure ExceptionHandler_MadExcept(const ExceptIntf : IMEException;
      var Handled : boolean);
which is this procedure:

Code: Select all

procedure TMainForm.ExceptionHandler_MadExcept(
  const ExceptIntf: IMEException; var Handled: boolean);
begin
{$IFDEF USE_MADEXCEPT}
  if ExceptIntf.ExceptObject is Exception then
    ExceptionHandler(Exception(ExceptIntf.ExceptObject), Handled);
{$ENDIF}    
end {TMainForm.ExceptionHandler_MadExcept};
and this is in FormCreate:

Code: Select all

{$IFDEF USE_MADEXCEPT}
  RegisterExceptionHandler(ExceptionHandler_MadExcept, stTrySyncCallOnSuccess);
{$ENDIF}
In FomCreate we also set the Application.OnException to this routine:

Code: Select all

procedure TMainForm.OnException(Sender: TObject; E: Exception);
  var
    Handled : boolean;
begin
  Handled := false;
  ExceptionHandler(E, Handled);
  if not Handled then begin
    E.Message := Format('%s (0x%s)', [E.Message, IntToHex(integer(ExceptAddr), 8)]);
    Application.ShowException(E);
  end {if};
end {TMainForm.OnException};
and ExceptionHandler is like this:

ExceptionHandler is:

Code: Select all

procedure TMainForm.ExceptionHandler(E: Exception; var Handled : boolean);
  begin
    Handled := true; // Assume

    if E is EBeep then begin
      MessageBeep(0)

    end else if E is EOutOfMemory then begin
      // ...

    end else if E is EOLESysError then begin
      // ...

    end else if E is EInOutError then begin
      with EInOutError(E) do
        // ...

    end else if E is ECheck then begin
      //...

    end else if E is EIOError then begin
      with EIOError(E) do
       //...

    end else if E is EHotSpotError then begin
      // ...

    end else if E is EExecException then begin
      // ...

    end else if E is EError then begin
      // ..

    end else if E is EGenError then begin
      // ...
    end else begin
      Handled := false;
    end {if};
end {TMainForm.ExceptionHandler};
thank you for your help.

Christian Aymon

Re: Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 2:33 pm
by madshi
I'm not sure what to say. You've posted your code, but I don't see a single question in your comment. Why did you post the code? Is it working? Or not working? I can't read your mind.

Re: Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 5:55 pm
by christian.aymon
The question is: How to configure and/or use MaxExcept so that it reports only certain exception classes (for example EAccessViolation) and not all classes, as it does today by default?

In other words, with this code...

Code: Select all

  raise Exception.Create('Message for the user'); // Or *many* other exception classes
...the exception has to be handled by the default handler, and I don't want MadExcept to trigger.

However, with this (fake code)...

Code: Select all

var
  p : ^Byte;
begin
  p := $0;
  p^ := 0; // <---- triggers AV exception
...MaxExcept should report the exception.

The Exception filters allows to exclude MadExcept handling for certain exception classes. But it does not allow to force explicitely MadExcept handling *only* for certain exception classes. We could, of course, filter out the 20+ classes that we want MaxExcept to ignore, but it would be much more easier to list only the 3 classes that we want MaxExcept to handle.

In my previous post, I also explained how we use exceptions in our code.

I also explained that we already discussed this topic in the past (6-8years), and at that time, you gave a solution that we implemented in our code. This implementation is still in place, these are the code snippets. However, this code is not active (the conditional is not defined) and I don't know how it would solve the issue.

Regards,

Christian Aymon

Re: Generate report only for certain exception classes

Posted: Mon Jan 30, 2017 6:03 pm
by madshi
You can do it by code or by using the settings dialog. If you have code in there but it's not active, how about activating it to see if it works? It looks ok to me on a quick check.

Alternatively, as I said before, the settings dialog does allow this kind of thing. There is a setting for "all other exception classes". So if you look again at the help page I linked to earlier, you would simply replace EEditDBError with EAccessViolation, and swap all other settings between the first and last/third section. So basically for EAccessViolation you'd get "show the full exception box", and for "all other exception classes" you'd get "show a simple message box".