#1199: Original Objective-C exceptions are lost when going through Ruby code. -------------------------------------+-------------------------------------- Reporter: eloy.de.enige@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Currently MacRuby will transform Objective-C exceptions into a Ruby RuntimeError and convert Ruby exceptions into Objective-C NSException instances. This means that you can't rescue an objc exception and re-raise it and expect the objc code to still be able to handle it. A discussion about this has lead to the conclusion that we should try to make Ruby exceptions inherit from NSException and no longer transform exceptions. Example code: {{{ $ cat test.m #import <Foundation/Foundation.h> void Init_test() {}; @interface MyError : NSException @end @implementation MyError @end @interface Test : NSObject @end @implementation Test - (void)raiseException { MyError *e = [[MyError alloc] initWithName:@"MyError" reason:@"Because I can" userInfo:nil]; @throw e; } - (void)callBlock:(id)block { @try { [block performSelector:@selector(call)]; } @catch(NSException *e) { NSLog(@"Exception class: %@, name: %@, reason: %@", [e class], [e name], [e reason]); } } @end $ cat test.rb require 'test.bundle' test = Test.new test.callBlock(proc { begin test.raiseException rescue Object => e p e raise e end }) $ gcc -o test.bundle -fobjc-gc -flat_namespace -undefined suppress -bundle -framework Foundation test.m }}} Current behavior: {{{ % macruby test.rb #<RuntimeError: MyError: Because I can> 2011-03-16 10:26:58.517 macruby[53938:903] Exception class: NSException, name: RuntimeError, reason: /Users/eloy/tmp/macruby-exception- ticket/test.rb:9:in `block': MyError: Because I can (RuntimeError) from /Users/eloy/tmp/macruby-exception-ticket/test.rb:4:in `<main>' }}} Expected behavior (as can be seen with attached naive patch): {{{ % macruby test.rb #<RuntimeError: MyError: Because I can> 2011-03-16 10:30:16.304 macruby[60162:903] Exception class: MyError, name: MyError, reason: Because I can }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1199> MacRuby <http://macruby.org/>