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

Reply via email to