[Gambas-user] Global error management routine
Tobias Boege
taboege at ...626...
Sun May 26 10:08:38 CEST 2013
On Sat, 25 May 2013, Beno?t Minisini wrote:
> Le 21/05/2013 16:13, Tobias Boege a ?crit :
> > Hi Benoit,
> >
> > when programming a component in C/C++, one can use the error hook to execute
> > a function when the interpreter is about to abort because of an error.
> >
> > In Gambas itself, we only have the local Catch blocks to execute code in
> > case of error in this or any context above in the stack.
> >
> > However, there is no global error handling routine like the above error hook
> > available for Gambas programs. It would be handy if the program ultimately
> > has to tidy up some of its business before it is killed.
> >
> > A rather dull example would be the one we initially intended: a Circular
> > from gb.data might be good to store program logs because it has a fixed
> > size. In case of an unexpected program error we would like to dump this
> > Circular. Easy when programming a component in C/C++ but impossible in
> > Gambas. AFAIK!
> >
> > Thoughts?
> >
> > Regards,
> > Tobi
> >
>
> Global error management routine has been implemented in revision #5678.
>
> This routine must be a static public method of the startup class, and
> must be named "Application_Error".
>
> Inside this method, you can use the properties of the Error class to get
> information about the error.
>
> If an uncatched error is raised while running Application_Error, then
> the program will abort with that error replacing the old one. Beware,
> this was not tested yet!
>
I did. This is my FMain.class:
---
Static Public Sub Application_Error()
Error "Error: "; Error.Text
Print 12 / 0
End
Public Sub Button1_Click()
File.Load("/does/not/exist")
End
---
What currently happens is that, when I click on Button1, Application_Error()
is called and prints the correct error. Then it produces an error and this
again calls Application_Error(). The error information is updated correctly.
However, the program does not abort until the Stack is exhausted.
> The IDE has been modified to try to save all modified files before
> aborting if an error occurs.
>
> Enjoy!
Yes. Good application in the IDE! I experienced IDE crashes sometimes, too.
AFAIR this was (almost) always in context of undoing some actions in the
form editor (most probably involving creating and destroying controls very
fast). Sadly, I couldn't reproduce this as the topic popped up recently.
Regards,
Tobi
More information about the User
mailing list