Joel VanderWerf wrote:
> Charles Mills wrote:
> > What techniques are available for handling errors that occur in
> > threads?
> >
> > For example how do I find out that an error occured in t below?
> >
> > t = Thread.new { raise "error" }
> >
> > I need to be able to check on the error status of threads from
their
> > parent.  Something like the following would be ideal - but I know
this
> > won't do what I want:
> >
> > begin
> > Thread.new { raise "error"}
> > rescue
> > puts $! # in a strange world prints "error", but in actuality does
> > nothing
> > end
>
> Another approach:
>
>    begin
>      Thread.new(Thread.current) do |th|
>        begin
>          raise "error"
>        rescue => e
>          th.raise e
>        end
>      end
>    rescue => e
>      p e
>    end

Perfect, that is exactly what I was looking for.  Basically my
situation is as follows:
####
..begin
..  Thread.new(Thread.current) do |th|
..    # do some processing
..    begin
..      raise "error"
..    rescue => e
..      th.raise e
..    end
..  end
..  # also do some processing
..rescue => e
..  puts e
..end
#### ignore leading dots - google groups seems to strip leading
whitespace :-/

Two threads asyncronously doing some processing, the child thread needs
to be able to notify the parent if errors occur during the processing
(rarely happens).  The details are explained here:
http://rubyforge.org/pipermail/dnssd-developers/2004-December/000000.html
Thanks,
Charlie