[Fxruby-users] Re: catching exceptions in event handlers
Status: Inactive
Brought to you by:
lyle
|
From: Emmanuel T. <emm...@wa...> - 2003-07-23 09:55:25
|
hmm now that i think about it more, wrapping the connect won't help.
maybe something like:
before :
def onOK()...
after:
def handler(symbol, &block)
# write me: generate method calling the block in a begin/rescue block
end
handler :onOK {
...
}
something like that.
i think this would work but would require changing my code.
anything better?
emmanuel
----- Original Message -----
From: "Emmanuel Touzery" <emm...@wa...>
To: <fxr...@li...>
Sent: Wednesday, July 23, 2003 11:54 AM
Subject: catching exceptions in event handlers
> Hello,
>
> 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.
> So it would seem i need to wrap each event handler in a begin/rescue
> block.
>
> 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
>
> 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?
>
> i'm sure i'm not the first one facing this problem?
>
> thank you,
>
> emmanuel
>
|