[Ironruby-core] Handling runtime errors in embedded applications

James Leskovar lists at ruby-forum.com
Sat Dec 26 06:12:34 EST 2009

Hi there,

So my application is basically a lightweight IDE for IronRuby, built in
C#, with the idea that users should be able to quickly edit and
prototype ruby scripts. Part of the application's requirements is to
have the ability to handle compilation/syntax errors and runtime
exceptions, as well as the ability to 'jump to' the source of errors.

At the moment, I'm wrapping CreateScriptSourceFromFile, Compile and
Execute within a try/catch. Syntax errors are easily handled with a
custom ErrorListener passed into ScriptSource.Compile. Handling runtime
errors though are a little bit more tricky; the easiest way I've found
so far involves RubyExceptionData.GetInstance and a linq expression to
parse the backtrace with regexes. Not the most elegant solution, but it

However, one area where this method falls flat is when the error occurs
in a thread created within the script itself; execution is now outside
the try/catch, so I'm not able to catch the Exception object.
Futhermore, nothing seems to happen when the error does occur; nothing
gets written to the errorstream, nor is there any indication of any
error. It seems like the only way to handle these thread errors is to do
it within the script using a begin-rescue block.

My question is, is there an easier way to get runtime error information
other than RubyExceptionData? Additionally, what is the best way to
handle errors when they occur in a thread other than the one which calls
Execute()? It would be handy to be able to set some sort of global
'ErrorListener', or perhaps have the ability to pass in such an object
to the call to Execute.

Kind regards,
Posted via http://www.ruby-forum.com/.

More information about the Ironruby-core mailing list