Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-05

Catching math exceptions in a DLL

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

OBones

Hello all,

Using FPC, I'm writing a DLL that exports functions used by a given host process.
In order to protect the host process, it is mandatory that all exceptions are trapped in the exported function and in order to achieve that, I have the following construct in all exported functions:

function SomeFunc(SomeParam: ParamType): Boolean;
begin
   Result := False;
   try
     // do the actual work
     Result := True;
   except
     on E: TObject do
       NotifyException(E);
   end;
end;

My problem comes when I have some code that does invalid math operations, like division by zero for instance.
In that case, the raised exception is never caught by my except statement and is directly sent to the host process, making it crash badly. Is there a way to have ALL exceptions caught, regardless of their origin?

Reply by email

Unknown author
to Unknown author

If I could just interject, How to build fpc with -dTEST_WIN64_SEH ? I've fpc/lazarus daily snapshoot, does -dTEST_WIN64_SEH in "project options"->"compiler options"->"other" will be enough for SEH support ?

best regards
tomek

Reply by email

Jonas Maebe
to Unknown author

t.wieckowski wrote on Wed, 16 May 2012:

If I could just interject, How to build fpc with -dTEST_WIN64_SEH ? I've fpc/lazarus daily snapshoot, does -dTEST_WIN64_SEH in "project options"->"compiler options"->"other" will be enough for SEH support ?

No. The compiler itself has to be recompiled with that option.

Jonas

Reply by email

Sven Barth
to Unknown author: Wasn't Sergei working on SEH under windows ? Michael.

Am 16.05.2012 13:35, schrieb

Show quoted text 16 lines
On Wed, 16 May 2012, Jonas Maebe wrote: > > OBones wrote on Wed, 16 May 2012: > >> Using FPC, I'm writing a DLL that exports functions used by a given >> host process. >> In order to protect the host process, it is mandatory that all >> exceptions are trapped in the exported function > > You are probably running into > http://bugs.freepascal.org/view.php?id=12974 Wasn't Sergei working on SEH under windows ?

But only for Win64, not Win32.

Regards,
Sven

Reply by email

OBones
to Jonas Maebe: OBones wrote on Wed, 16 May 2012: You are probably running into…
Jonas Maebe wrote 10 lines
OBones wrote on Wed, 16 May 2012: > Using FPC, I'm writing a DLL that exports functions used by a given > host process. > In order to protect the host process, it is mandatory that all > exceptions are trapped in the exported function You are probably running into http://bugs.freepascal.org/view.php?id=12974

Yes, looks like it indeed.
I'll experiment with the proposed solutions

Reply by email