[fxruby-users] FXRuby default error handler

Meinrad Recheis meinrad.recheis at gmail.com
Mon Oct 8 16:56:04 EDT 2007


On 10/8/07, Joel VanderWerf <vjoel at path.berkeley.edu> wrote:
> Philippe Lang wrote:
> > Hi,
> >
> > I'm using FXRuby for building a database front-end. I have quite a lot
> > of classes now, made up of multiple methods each. Most of the time I use
> > rescue blocks in case an exception is raised by the framemork. But doing
> > that in every method of every class is really tedious.
> >
> > If an exception is raised from a method without a rescue block, the
> > problem is that my application quits, since the application "run" method
> > stops.
> >
> >
> >   begin
> >
> >     $app = MyApp.new
> >     $app.create
> >     $app.run
> >
> >   rescue Exception => e
> >
> >     DbError.show("", e)
> >
> >   end
> >
> >
> > I was wondering if we could define some sort of "default error handler"
> > for errors raised from the framework, in order to avoid both the
> > application crash, and the "one rescue per method" solution...
>
> That's a good question.
>
> I usually just try to make "one rescue per method" as painless as
> possible, by writing wrapper methods. Still, that's "one wrapper per
> method", which is only a slight improvement.
>

Try to centralize access to the DB. Channel all method calls to the DB
through one dedicated method that handles db errors. something like
this could do the job:

class DB
def safe_call( method, *args, &block)
self.send( method, *args, &block)
rescue DBError
# all db errorhandling here
end
end

there might be even better solutions

-- meinrad


More information about the fxruby-users mailing list