How to append additional informations like in madExcept v2x?

delphi package - automated exception handling
Post Reply
kaju74
Posts: 24
Joined: Thu Nov 18, 2004 1:48 pm

How to append additional informations like in madExcept v2x?

Post by kaju74 »

Hi...

In madExcept v2.x, I've wrote the following code to append some additional lines to bug report:

Code: Select all

procedure ExceptionFilter(Frozen: Boolean; ExceptObject: TObject; ExceptAddr: Pointer;
 CashedThreadId : dword; var BugReport: string; var ScreenShot: string;
 var CanContinue: Boolean; var Handled: Boolean);
begin
  { attach license-informations to bug report }
  if ExceptObject <> nil then
  with Planner.Enviroment.License do
    begin
      BugReport := Format(
        'license holder    : %s' + #13#10 +
        'pharmacy name     : %s' + #13#10 +
        'owner name        : %s' + #13#10 +
        'address           : %s' + #13#10 +
        BugReport, [UserName, PharmacyName, OwnerName, Address]
      );
    end;
end;
But this doesn't work in ME3 anymore? I've noticed the new header of this event:

Code: Select all

procedure ExceptionFilter(const exceptIntf : IMEException; var Handled : Boolean);
...but don't know what to do with "exceptIntf". I've tryed "exceptIntf.BugReport := exceptIntf.BugReport + ..." but this doesn't work.

How to solve this w/o the new assistants? (I need to append these lines silently)...

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

Post by madshi »

Code: Select all

  with Planner.Enviroment.License, exceptIntf do
    begin
      BugReportHeader['license holder'] := UserName;
      BugReportHeader['pharmacy name' ] := PharmacyName;
      BugReportHeader['owner name'    ] := OwnerName;
      BugReportHeader['address'       ] := Address;
    end; 
kaju74
Posts: 24
Joined: Thu Nov 18, 2004 1:48 pm

Post by kaju74 »

Thank you for this fast response, but did I had to do anything else inside this event handler because the additional informations were not applied to the final report?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Are you sure that they weren't added? They are not on top of the header and also not on the bottom, but somewhere in the midst (close to the bottom). I chose that place to add new header information because I think the information at the top should always be the same. And the information at the bottom (exception class and message) belong to the callstacks and so should be placed near to them.
kaju74
Posts: 24
Joined: Thu Nov 18, 2004 1:48 pm

Post by kaju74 »

No, they weren't attached! But, if I return "Handled := False;" they were attached BUT at this point, ME also comes up FOR EVERY already handled exception... :confused:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Hmmmm... Now I'm a bit confused. So you're saying when you set "handled := false" the madExcept exception box appears twice? Or what do you mean? Can you tell me a bit more about what you're doing? Did you set "handled := true" somewhere or what?

How does your "RegisterExceptionHandler" call look like?
kaju74
Posts: 24
Joined: Thu Nov 18, 2004 1:48 pm

Post by kaju74 »

Okay. I've a datamodule which will be created at first in my application with the following initialization code:

Code: Select all

initialization
  { register exception handler }
  RegisterHiddenExceptionHandler(ExceptionFilter, stDontSync);
the exception handler is implemented as followed:

Code: Select all

{$IFDEF USE_MADEXCEPT_3}
procedure ExceptionFilter(const exceptIntf : IMEException; var Handled : Boolean);
{$ELSE}
procedure ExceptionFilter(Frozen: Boolean; ExceptObject: TObject; ExceptAddr: Pointer;
 CashedThreadId : dword; var BugReport: string; var ScreenShot: string;
 var CanContinue: Boolean; var Handled: Boolean);
{$ENDIF}
begin
  { attach license-informations to bug report }
{$IFDEF USE_MADEXCEPT_3}
  with Planner.Enviroment.License, exceptIntf do
    begin
      BugReportHeader['license holder'] := UserName;
      BugReportHeader['pharmacy name' ] := PharmacyName;
      BugReportHeader['owner name'    ] := OwnerName;
      BugReportHeader['address'       ] := Address;
    end;
{$ELSE}
  if ExceptObject <> nil then
  with Planner.Enviroment.License do
    begin
      BugReport := Format(
        'license holder    : %s' + #13#10 +
        'pharmacy name     : %s' + #13#10 +
        'owner name        : %s' + #13#10 +
        'address           : %s' + #13#10 +
        BugReport, [UserName, PharmacyName, OwnerName, Address]
      );
    end;
{$ENDIF}
end;
The compiler-directive is set to use ME3! I've created a simple button which creates a sample exception. If I click on it, ME3 pops up and show me the error but W/O any additional informations. If I modify the code as followed...

Code: Select all

  with Planner.Enviroment.License, exceptIntf do
    begin
      BugReportHeader['license holder'] := UserName;
      BugReportHeader['pharmacy name' ] := PharmacyName;
      BugReportHeader['owner name'    ] := OwnerName;
      BugReportHeader['address'       ] := Address;
    end;
  Handled := False; // <- THIS LINE WAS ADDED!
...ME3 pops up (as before) BUT WITH the additional informations included - that's fine for now, but....

now, everytime a SILENT exception occurs, ME3 pop up, too!!! I've some places in my app where I handle exceptions by myself like:

Code: Select all

  try
    // do something which may occur in an exception
    ...
  except
    { catch all errors }
  end;
ME3 will now also occur on THIS exceptions! If I remove the line "Handled := False;", my already handled exceptions will be proceeded fine and ME3 only pop's up on UNHANDLED exceptions, BUT NO additional informations are added!

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

Post by madshi »

Do you want to catch hidden (handled) exceptions at all? I think you should replace "RegisterHiddenExceptionHandler" with "RegisterExceptionHandler".
kaju74
Posts: 24
Joined: Thu Nov 18, 2004 1:48 pm

Post by kaju74 »

:crazy: :crazy: :blush: :oops: :crazy: :crazy:

MY FAILURE! Sorry, but the whole story comes from a simple drag&drop paste error from your sample html-code!!!! With "RegisterExceptionHandler" everything works as expected! Thank you for your support..... :oops: :oops: :oops:
Post Reply