Sign in Join

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

Mailing lists / lazarus / 2010-02

How to use ExceptProc and application.CaptureExceptions

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Alexander Grau

Hello,

I'm trying to turn off application exception capturing (so I can send exception traces via HTTP in bug reports):

1) In (the first loaded unit of) a console app, I did override ExceptProc (see code at bottom) - my own handler is called (as expected) on a EDivByZero exception.

2) In my Lazarus LCL app (SVN 23483M, LCL/Win32/i386, fpc 2.4.0), I did the same like in the console app - additionally, I did set Application.CaptureExceptions to 'false':

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  application.CaptureExceptions:=false;
  Application.Run;

Now, when a EDivByZero is raised, my own handler is *not* called - instead the default TApplication.HandleException is called - To my surprise...
a) When raised before Application.Run, my own handler is called (as it should).
b) When I debug Application.Run, it correctly uses the case without exception handling(!) - that is, it correctly detects the CaptureExceptions change.
c) When I read ExceptProc right before the exception, it correctly has the value of my own handler(!)

Though, my own handler is never called within Application.Run - and I have no idea why...

Any help or ideas are welcome!

Thanks,
Alexander

---------------Console output------------------------

install
application.CaptureExceptions=0
TApplication.HandleException Division by zero
Stack trace:
$00420413 CRASHME, line 39 of unit1.pas
$0042047A TFORM1__BUTTONCRASHMECLICK, line 46 of unit1.pas $004C6234 TCONTROL__CLICK, line 2294 of ./include/control.inc $004FA26F TBUTTONCONTROL__CLICK, line 72 of ./include/buttoncontrol.inc $004FA745 TCUSTOMBUTTON__CLICK, line 164 of ./include/buttons.inc $004FACA1 TBUTTON__CLICK, line 331 of ./include/buttons.inc $004FA10A TBUTTONCONTROL__WMDEFAULTCLICKED, line 26 of ./include/buttoncontrol.inc
$0040A84A
$004BCE72 TWINCONTROL__WNDPROC, line 5102 of ./include/wincontrol.inc $0050FCC7 DELIVERMESSAGE, line 111 of lclmessageglue.pas $004DB6B0 WINDOWPROC, line 2621 of win32callback.inc $77D18709
$77D187EB
$77D1B743
$77D1B7AB
$773C6FF6
$773C70D8

-----------My exception handler---------------------

procedure MyExceptionHandler(
  Obj : TObject;       // ExceptObject
  Addr: Pointer;       // ExceptAddr
  FrameCount: Longint; // ExceptFrameCount
  Frames: PPointer     // ExceptFrames
);
begin
  writeln('MyExceptionHandler');
  ShowException(obj, addr);
end;
initialization
  writeln('install');
  exceptproc := @MyExceptionHandler;
Mit freundlichen Gr??en/Best regards Alexander Grau Grau GbR Hardware & Software Solutions Eschenweg 12 32609 Huellhorst Germany www.grauonline.de Tel: +49 (0) 5741 2301259 Fax: +49 (0) 5741 235530 E-Mail:

Reply by email

Alexander Grau
to Alexander Grau

I'm answering my own question since I got it solved now by setting an ExceptionHandler using Application.AddOnExceptionHandler:

    application.AddOnExceptionHandler(@MyExceptionHandler);

This will capture exceptions, however a stack trace with line numbers won't work yet because the default handler is still called and will output a stack trace with line info, but the 'lineinfo' procedure cannot generate a 2nd, 3rd etc. stack trace with line info (for some unknown reason).

The default handlers can be disabled setting a flag:

Application.Flags=[AppNoExceptionMessages]

That did the trick. Then the stack trace is available with line info for at least one time!

Cheers,
Alexander

Show quoted text 85 lines
Hello, I'm trying to turn off application exception capturing (so I can send exception traces via HTTP in bug reports): 1) In (the first loaded unit of) a console app, I did override ExceptProc (see code at bottom) - my own handler is called (as expected) on a EDivByZero exception. 2) In my Lazarus LCL app (SVN 23483M, LCL/Win32/i386, fpc 2.4.0), I did the same like in the console app - additionally, I did set Application.CaptureExceptions to 'false': Application.Initialize; Application.CreateForm(TForm1, Form1); application.CaptureExceptions:=false; Application.Run; Now, when a EDivByZero is raised, my own handler is *not* called - instead the default TApplication.HandleException is called - To my surprise... a) When raised before Application.Run, my own handler is called (as it should). b) When I debug Application.Run, it correctly uses the case without exception handling(!) - that is, it correctly detects the CaptureExceptions change. c) When I read ExceptProc right before the exception, it correctly has the value of my own handler(!) Though, my own handler is never called within Application.Run - and I have no idea why... Any help or ideas are welcome! Thanks, Alexander ---------------Console output------------------------ install application.CaptureExceptions=0 TApplication.HandleException Division by zero Stack trace: $00420413 CRASHME, line 39 of unit1.pas $0042047A TFORM1__BUTTONCRASHMECLICK, line 46 of unit1.pas $004C6234 TCONTROL__CLICK, line 2294 of ./include/control.inc $004FA26F TBUTTONCONTROL__CLICK, line 72 of ./include/buttoncontrol.inc $004FA745 TCUSTOMBUTTON__CLICK, line 164 of ./include/buttons.inc $004FACA1 TBUTTON__CLICK, line 331 of ./include/buttons.inc $004FA10A TBUTTONCONTROL__WMDEFAULTCLICKED, line 26 of ./include/buttoncontrol.inc $0040A84A $004BCE72 TWINCONTROL__WNDPROC, line 5102 of ./include/wincontrol.inc $0050FCC7 DELIVERMESSAGE, line 111 of lclmessageglue.pas $004DB6B0 WINDOWPROC, line 2621 of win32callback.inc $77D18709 $77D187EB $77D1B743 $77D1B7AB $773C6FF6 $773C70D8 -----------My exception handler--------------------- procedure MyExceptionHandler( Obj : TObject; // ExceptObject Addr: Pointer; // ExceptAddr FrameCount: Longint; // ExceptFrameCount Frames: PPointer // ExceptFrames ); begin writeln('MyExceptionHandler'); ShowException(obj, addr); end; initialization writeln('install'); exceptproc := @MyExceptionHandler;
Mit freundlichen Gr??en/Best regards Alexander Grau Grau GbR Hardware & Software Solutions Eschenweg 12 32609 Huellhorst Germany www.grauonline.de Tel: +49 (0) 5741 2301259 Fax: +49 (0) 5741 235530 E-Mail:

Reply by email

Bogusław Brandys
to Alexander Grau

Alexander Grau pisze:

Show quoted text 11 lines
I'm answering my own question since I got it solved now by setting an ExceptionHandler using Application.AddOnExceptionHandler: application.AddOnExceptionHandler(@MyExceptionHandler); This will capture exceptions, however a stack trace with line numbers won't work yet because the default handler is still called and will output a stack trace with line info, but the 'lineinfo' procedure cannot generate a 2nd, 3rd etc. stack trace with line info (for some unknown reason).

Bug in lineinfo processing. I posted a patch long time ago but it seems nobody is interested.Now it would require also to fix dwarf lineinfo.

Boguslaw

Reply by email

Flávio Etrusco
to Bogusław Brandys

2010/2/17 Bogus?aw Brandys :

Show quoted text 19 lines
Alexander Grau pisze: > > I'm answering my own question since I got it solved now by setting an > ExceptionHandler using Application.AddOnExceptionHandler: > > ? application.AddOnExceptionHandler(@MyExceptionHandler); > > This will capture exceptions, however a stack trace with line numbers > won't work yet because the default handler is still called and will output a > stack trace with line info, but the 'lineinfo' procedure cannot generate a > 2nd, 3rd etc. stack trace with line info (for some unknown reason). > Bug in lineinfo processing. I posted a patch long time ago but it seems nobody is interested.Now it would require also to fix dwarf lineinfo. Boguslaw

Is there a mantis entry for this? If not please create it or send the patch again (so I create it).
Many thanks.

-Fl?vio

Reply by email

Bogusław Brandys
to Flávio Etrusco

Fl?vio Etrusco pisze:

Show quoted text 25 lines
2010/2/17 Bogus?aw Brandys : > Alexander Grau pisze: >> I'm answering my own question since I got it solved now by setting an >> ExceptionHandler using Application.AddOnExceptionHandler: >> >> application.AddOnExceptionHandler(@MyExceptionHandler); >> >> This will capture exceptions, however a stack trace with line numbers >> won't work yet because the default handler is still called and will output a >> stack trace with line info, but the 'lineinfo' procedure cannot generate a >> 2nd, 3rd etc. stack trace with line info (for some unknown reason). >> > > Bug in lineinfo processing. I posted a patch long time ago but it seems > nobody is interested.Now it would require also to fix dwarf lineinfo. > > Boguslaw > Is there a mantis entry for this? If not please create it or send the patch again (so I create it). Many thanks. -Fl?vio

http://bugs.freepascal.org/view.php?id=13518

It maybe now obsolete though.I'm not conversant with current svn changes.

Boguslaw

Reply by email