Moved to berlin 10.1 and madexcept stopped working

delphi package - automated exception handling
Post Reply
emailaya
Posts: 249
Joined: Thu Oct 13, 2005 11:33 am
Contact:

Moved to berlin 10.1 and madexcept stopped working

Post by emailaya »

Hi

I have a project that was working great with madexcept in XE3.
I now moved to XE10.1 and my project works OK. I simulated an error in the code to make sure madexcept is working (with the same settings) but nothing really happens when the error occurred (a simple division by 0 or using a tstringlist without first creating it).

my code is basically the following

Code: Select all

initialization
  RegisterExceptionHandler(frmMain.ExceptionFilter, stTrySyncCallOnSuccess);
  madexcept.InstallUnhandledExceptionFilter();

private
  procedure ExceptionFilter(const exceptIntf: IMEException; var Handled: Boolean);

procedure TfrmMain.ExceptionFilter(const exceptIntf: IMEException; var Handled: Boolean);
var
  res: string;
  Values: array [0 .. 0] of string;
begin
  try
    Handled := True;  <<<<<<<<<<<<<<<<<<<<<<<<<<<
.
.
.
end;
I put a breakpoint in the marked line above but it didn't even got there.
If I raise Exception.Create('blah blah'); then it works as expected.

A simple code I was using

Code: Select all

procedure TfrmMain.Button1Click(Sender: TObject);
var a,b: extended;
begin
a := 10/0; <<<< I expected for it to fail here
b := a + 1;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
var tmp: tstringlist;
begin
tmp.text := 'dddd'; <<<<< I expected for it to fail here
end;
What am I missing?
Thanks
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Moved to berlin 10.1 and madexcept stopped working

Post by madshi »

If you run this in the IDE debugger, does the debugger report an exception? Or does it run through without any complaints?
emailaya
Posts: 249
Joined: Thu Oct 13, 2005 11:33 am
Contact:

Re: Moved to berlin 10.1 and madexcept stopped working

Post by emailaya »

I run it using the debugger but I thought madexcept "ovverides" the debugger to do its magic

I expected to see a "division by zero" or "access violation" error but saw neither. Any idea why?

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

Re: Moved to berlin 10.1 and madexcept stopped working

Post by madshi »

The IDE debugger usually catches the exceptions first, and only if you press "continue", madExcept becomes active. The reason for that is that madExcepts only cares about unhandled exceptions, so madExcept waits until it knows for sure if the exception is handled or unhandled. The IDE debugger stops in the very moment the exception is raised, so it's earlier.

There's a CPU option that defines whether floating point errors raise exceptions or not. I'm not sure which the default behaviour is with which Delphi version. Try using integer instead of extended, and "div" instead of "/". Then you should see the exception. Your other crash case depends on a random "tmp" value. I suppose depending on what value "tmp" randomly has, it might crash or not.

I'm usually using "integer(nil^) := 0" to test for OS exceptions. That must always crash.
emailaya
Posts: 249
Joined: Thu Oct 13, 2005 11:33 am
Contact:

Re: Moved to berlin 10.1 and madexcept stopped working

Post by emailaya »

Thanks for the detailed explanation
Post Reply