Jano Svitok
9/19/2007 6:17:00 PM
On 9/19/07, Chris Hall <christopher.k.hall@gmail.com> wrote:
> Here's my situation
> and this works...however, the difference is that if an exception is
> thrown as part of the Task's action (when it is run) eval craps out with
> an exception like
>
> (eval):15
>
> and it brings down the entire script, which is a bad thing because i'm
> running each task in a thread. this doesn't happen obviously when i'm
> not eval'ing.
You can handle those exceptions by adding 'rescue' clause to your run method.
i.e.
def run
begin
@action.call...
rescue Exception => ex
# do whatever you want with ex
end
end
You have to
Note: in this case the begin and end may be omitted:
def run
@action.call...
rescue Exception => ex
# do whatever you want with ex
end
To catch syntax errors, you have to add begin/rescue/end around the
eval command.
Have a look at ruby exception hierarchy in zenspider's Ruby QuickRef,
and carefully consider what do you want to catch and what not (to
allow ctrl-break to function etc.)
Finally, you can control exception propagation using Thread.abort_on_exception.
HTH,
Jano