From: Jano Svitok Date: 2007-09-20T03:17:15+09:00 Subject: Re: exceptions and eval'ing a string On 9/19/07, Chris Hall 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