Re: [Fxruby-users] catching exceptions in event handlers
Status: Inactive
Brought to you by:
lyle
|
From: Lyle J. <jl...@cf...> - 2003-07-23 13:03:30
|
Emmanuel Touzery wrote:
> I'm having the problem that my GUI app might have some bugs; in that
> case, instead of seeing it exiting violently, dumping the stack on the
> command line (which will never be seen by the user in most cases), i would
> like to catch the exception and display a nice dialog box.
> Wrapping the app.run call (i don't remember how it's called, but it's
> something like that) in a begin/rescue block doesn't seem to catch this
> exception.
Is it a standard Ruby exception, or is the Ruby interpreter (ruby)
seg-faulting? If it's the former (a regular exception), it /should/ be
raised all the way to the "top" and get caught in your begin-rescue
block around the call to FXApp#run.
> So it would seem i need to wrap each event handler in a begin/rescue
> block.
You might also see if the Fox.setIgnoreExceptions() method is a suitable
workaround; see the "Debugging Tricks" at the end of this page:
http://www.fxruby.org/doc/differences.html
> I thought about something like (didn't look at the code, untested
> snippet, just to give the idea):
>
> class FXWindow
> def connect(event, &block)
> begin
> super
> rescue
> FXMessageBox("an error occured, here is the stacktrace, contact
> the developer of the application"...)
> exit
> end
> end
> end
No, this wouldn't work. The connect() method just sets up the mapping
between a message type (e.g. SEL_COMMAND) and the block or method that
handles it. It doesn't actually execute the code.
> and the same for other ways to connect the events (ie event tables). i would
> put that in a "exceptionfox.rb", and do a "require 'exceptionfox.rb'"
> instead of "require 'fox'", so i wouldn't have to change my code. i could
> also call a user-defined function when getting an exception.
> i didn't try this approach yet (no time). but i'm wondering if it seems
> possible, and if there is maybe a better solution?
This sounds way too complicated, IMO. If wrapping the call to FXApp#run
with a "last-chance" begin-rescue block is failing to catch exceptions,
I would like to see that demonstrated and get it fixed. I think the best
solution is to get a good group of testers and get them to help you find
the bugs ;)
|