UnhandledException *does* have the feature to not terminate the process; you need to do "e.Handled = true;" in your exception handler to tell the CLR that the exception has been properly handled. If you don't set it, the CLR doesn't see the exception as handled and continues propagating the exception, which will eventually terminate the process.
I was pretty sure it worked for Threads as well, since all threads are still bound to the current AppDomain, but let me know if your fixed exception handler still doesn't solve this. However, your work-around will work in the meantime. ~js ________________________________________ From: ironruby-core-boun...@rubyforge.org [ironruby-core-boun...@rubyforge.org] on behalf of James Leskovar [li...@ruby-forum.com] Sent: Tuesday, December 29, 2009 4:26 PM To: ironruby-core@rubyforge.org Subject: Re: [Ironruby-core] Handling runtime errors in embedded applications Unfortunantly, the problem with setting the unhandled exception event is that there's no way to 'recover' from the exception; the application terminates immediately after the event. Additionally, this method doesn't seem to work for exceptions within threads: class Program { static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler); Console.WriteLine("Creating engine"); var engine = Ruby.CreateEngine(); engine.Execute("Thread.start { puts 'raising exception...'; raise Exception, 'my exception'; puts 'not reached'; }"); Console.WriteLine("Done"); Console.ReadKey(true); } static void MyExceptionHandler(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("Caught " + ((Exception)e.ExceptionObject).Message); } } On my box (IronRuby 0.9.2, .NET 3.5sp1), the output is Creating engine Done raising exception... and then blocks on the call to ReadKey, without ever calling MyExceptionHandler. Again, the current workaround is to use a begin-rescue inside the thread proc, which isn't too terrible. One possible solution would probably be to reopen Thread.start so that it wraps the given block with begin-rescue, and then pass the exception object onto my host object for invoking onerror events. Jimmy Schementi wrote: > To solve this, you can hook the > CLR's ApplicationUnhandedException event to catch all exceptions from > code executing in an AppDomain: -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core