Sign in Join

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

Mailing lists / fpc-pascal / 2015-03

Exceptions in Library

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

steveg

Would anybody be able to enlighten me on enabling exception trapping in Linux libraries ?

As far as I can tell, exceptions propagate through to the main app - (written with Lazarus in this case).
I would like to trap them directly within the library.

Pointers, clues, links, examples (heck, even full source) really appreciated :)

Thanks - SteveG

leledumbo
to steveg
As far as I can tell, exceptions propagate through to the main app - (written with Lazarus in this case). I would like to trap them directly within the library.
// excp.pas
library excp;
{$mode objfpc}
uses sysutils;
procedure p;
begin
  try
    raise exception.create('an exception')
  except
    on e: exception do
      writeln(e.message);
  end;
end;
exports p;
end.
// test.pas
procedure p; external 'excp';

begin p end.

run with:
$ LD_LIBRARY_PATH=. ./test

you should get:
an exception

tested on ManjaroLinux 64-bit.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Exceptions-in-Library-tp5721521p5721522.html Sent from the Free Pascal - General mailing list .
steveg
to leledumbo
leledumbo wrote 37 lines
> As far as I can tell, exceptions propagate through to the main app - > (written with Lazarus in this case). > I would like to trap them directly within the library. // excp.pas library excp; {$mode objfpc} uses sysutils; procedure p; begin try raise exception.create('an exception') except on e: exception do writeln(e.message); end; end; exports p; end. // test.pas procedure p; external 'excp'; begin p end. run with: $ LD_LIBRARY_PATH=. ./test you should get: an exception tested on ManjaroLinux 64-bit.

Tested this, and you are correct - it captures it correctly After further testing - It would seem to capture some but not others ?

(contrived example - I know not to directly call a control within a library) this doesnt seem to be trapped - drops thru to main app

   try
     Str1 := TControl(0).Name;
   except
     on e: exception do
       writeln(e.message);
   end;

Would this suggest a different signal attachment is necessary ?

Thanks