View Full Version : exiting application from exception handler
davec_ias
24-Mar-2006, 09:26 PM
I have a created a subclass of EurekaLog that shows a dialog with some stack trace info and has a property OnAfterExceptionNotify which allows client code to perform actions after the dialog has been shown and closed.
When I try to put something like:
Form1.Close;
or
Application.Terminate;
in this handler from the client code, the application simply ignores this (but things like ShowMessage work fine). Similar behavior exists for the normal TEurekaLog when I put the form closing code in the handler of ExceptionNotify.
Is there something about the exception handling behavior that would prevent the form from closing in these cases?
Dave
davec_ias
24-Mar-2006, 09:27 PM
I should have included this above - I'm using win32 via delphi 7 with eureka 4.6.7 RC 2 enterprise.
admin
27-Mar-2006, 02:26 PM
davec_ias wrote:
> I have a created a subclass of EurekaLog that shows a dialog with some
> stack trace info and has a property OnAfterExceptionNotify which allows
> client code to perform actions after the dialog has been shown and
> closed.
>
> When I try to put something like:
>
> Form1.Close;
>
> or
>
> Application.Terminate;
>
> in this handler from the client code, the application simply ignores
> this (but things like ShowMessage work fine). Similar behavior exists
> for the normal TEurekaLog when I put the form closing code in the
> handler of ExceptionNotify.
>
> Is there something about the exception handling behavior that would
> prevent the form from closing in these cases?
>
> Dave
I think no.
Can you send to me a little source demo able to reproduce your problem,
so to help me to help you? :)
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!
davec_ias
27-Mar-2006, 06:18 PM
Create a brand new application, drop a EurekaLog component and two buttons onto the form. Implement handlers as below:
procedure TForm1.EurekaLog1ExceptionNotify(
EurekaExceptionRecord: TEurekaExceptionRecord; var Handled: Boolean);
begin
Form1.Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
raise Exception.Create('error message goes here');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Close;
end;
Both buttons should cause the form to close, the first one as a result of the eureka hander, the second as a direct result of the button push handler. THe first button causes the eureka dialog to appear (as one might expect) but the form remains open (as one might not expect). The second button closes the form as expected.
thanks,
Dave
admin
28-Mar-2006, 09:11 AM
Hi,
davec_ias wrote:
> Create a brand new application, drop a EurekaLog component and two
> buttons onto the form. Implement handlers as below:
>
> [...]
>
> Both buttons should cause the form to close, the first one as a result
> of the eureka hander, the second as a direct result of the button push
> handler. THe first button causes the eureka dialog to appear (as one
> might expect) but the form remains open (as one might not expect). The
> second button closes the form as expected.
>
> thanks,
> Dave
Every EurekaLog events is executed in a separated thread, this to can
increase the security of a correct execution. In fact the exception
thread can be unstable due the exception.
So when you call the "TForm.Close" method you call a VCL method (that
isn't thread safe) in a multi thread environment.
This is the reason why it did not works if called into an EurekaLog event.
If you want you can bypass this problem creating a Thread wrapper and
calling the TForm.Close method into the TThread.Execute method (using
the Synchronize calling).
But also obtaining to close the Form into an EurekaLog event, the
EurekaLog dialog will be showed only as a simple MessageBox.
This because closing the main form you remove all GUI resources required
from EurekaLog to can shows its dialog.
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!
davec_ias
28-Mar-2006, 04:13 PM
I didn't realize that the handling was done in a separate thread. So I changed the code to use PostMessage (tried SendMessage too).
procedure TForm1.EurekaLog1ExceptionNotify(
EurekaExceptionRecord: TEurekaExceptionRecord; var Handled: Boolean);
begin
//SendMessage(Form1.Handle, WM_CLOSE, 0, 0);
PostMessage(Form1.Handle, WM_CLOSE, 0, 0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
raise Exception.Create('error message goes here');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//SendMessage(Form1.Handle, WM_CLOSE, 0, 0);
PostMessage(Form1.Handle, WM_CLOSE, 0, 0);
end;
It still has no effect. I've even verified that the OnCLoseQuery and OnClose handlers are indeed executed in response to the message posted from the exception handler. However the form doesn't actually close in response to the excetion (but does close in response to a simple button 2 press). Ideas? I simply want to close the app on an unexpected exception.
Dave
admin
30-Mar-2006, 02:58 PM
Hi,
davec_ias wrote:
> I didn't realize that the handling was done in a separate thread. So I
> changed the code to use PostMessage (tried SendMessage too).
>
> procedure TForm1.EurekaLog1ExceptionNotify(
> EurekaExceptionRecord: TEurekaExceptionRecord; var Handled: Boolean);
> begin
> //SendMessage(Form1.Handle, WM_CLOSE, 0, 0);
> PostMessage(Form1.Handle, WM_CLOSE, 0, 0);
> end;
>
> procedure TForm1.Button1Click(Sender: TObject);
> begin
> raise Exception.Create('error message goes here');
> end;
>
> procedure TForm1.Button2Click(Sender: TObject);
> begin
> //SendMessage(Form1.Handle, WM_CLOSE, 0, 0);
> PostMessage(Form1.Handle, WM_CLOSE, 0, 0);
> end;
>
> It still has no effect. I've even verified that the OnCLoseQuery and
> OnClose handlers are indeed executed in response to the message posted
> from the exception handler. However the form doesn't actually close in
> response to the excetion (but does close in response to a simple button
> 2 press). Ideas? I simply want to close the app on an unexpected
> exception.
>
> Dave
You can simply obtain this using the ExceptionActionNotify event at the
"atSavedLogFile" action instead of ExceptionNotify event.
This action is called after that EurekaLog has showed its info and saved
its log.
See the following example:
procedure TForm1.EurekaLog1ExceptionActionNotify(
EurekaExceptionRecord: TEurekaExceptionRecord;
EurekaAction: TEurekaActionType; var Execute: Boolean);
begin
if (EurekaAction = atSavedLogFile) then
PostMessage(Form1.Handle, WM_CLOSE, 0, 0);
end;
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.