On 11/8/06, Jan Svitok <jan.svitok / gmail.com> wrote:
> On 11/8/06, Paul Lutus <nospam / nosite.zzz> wrote:
> > Leslie Viljoen wrote:
> >
> > > I have a script that needs to run unattended every night, and I need
> > > to log if it throws an exception anywhere. Is this as simple as
> > > putting a begin..rescue..end around the top-most statements? I know
> > > that doesn't work in C#. Is there a hook or some way that a catch-all
> > > is supposed to be done in Ruby?
> > >
> > > Les
> >
> > This should catch everything, AFAIK:
> >
> > begin
> >   ...
> > rescue Exception => err
> >   puts err
> > end
> >
> > If there is nothing but function calls between "begin" and "rescue", e.g. if
> > the entire executable block lies there, this should do it.
>
> You should put this begin...rescue...end around each thread body you
> start, unless you set
> Thread.abort_on_exception = true. Otherwise exceptions in other
> threads might get lost.
>
> Finally I'll mention that rescue without parameter rescues only
> StandardError, and therefore doesn't catch all Exceptions.

Thanks, that helps.