Projects

Ticket #627 (closed defect: fixed)

Opened 2 years ago

Last modified 21 months ago

Obj-C exception raised within a rescue block are not catched

Reported by: martinlagardette@… Owned by: lsansonetti@…
Priority: major Milestone: MacRuby 0.7
Component: MacRuby Keywords: rescue exception
Cc: ernest.prabhakar@…, martinlagardette@…

Description

This file:

# test.rb
begin
  begin
    raise
  rescue
    NSString.stringWithCString(nil)
  end
rescue
  puts "rescued"
end

Will produce the following:

$> macruby /tmp/test.rb
uncaught Objective-C/C++ exception...
2010-03-01 22:45:58.926 macruby[30392:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithCString:]: NULL cString'
*** Call stack at first throw:
(
        0   CoreFoundation                      0x00007fff84f80444 __exceptionPreprocess + 180
        1   libobjc.A.dylib                     0x00007fff84db80f3 objc_exception_throw + 45
        2   CoreFoundation                      0x00007fff84f80267 +[NSException raise:format:arguments:] + 103
        3   CoreFoundation                      0x00007fff84f801f4 +[NSException raise:format:] + 148
        4   Foundation                          0x00007fff87f704ed +[NSString stringWithCString:] + 80
        5   ???                                 0x0000000101040385 0x0 + 4312007557
        6   libmacruby.dylib                    0x0000000100174130 rb_vm_dispatch + 2688
        7   ???                                 0x000000010104015d 0x0 + 4312007005
        8   libmacruby.dylib                    0x0000000100184ebf rb_vm_run + 351
        9   libmacruby.dylib                    0x0000000100046459 ruby_run_node + 73
        10  macruby                             0x0000000100000d28 main + 152
        11  macruby                             0x0000000100000c88 start + 52
        12  ???                                 0x0000000000000002 0x0 + 2
)
terminate called after throwing an instance of 'NSException'
Abort trap

However, using pure Ruby exceptions works without issue:

# test2.rb
begin
  begin
    raise
  rescue
    raise
  end
rescue
  puts "rescued"
end
$> macruby /tmp/test2.rb
rescued

Change History

Changed 2 years ago by ernest.prabhakar@…

  • cc ernest.prabhakar@… added

Cc Me!

Changed 2 years ago by martinlagardette@…

  • cc martinlagardette@… added

Cc Me!

Changed 21 months ago by martinlagardette@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.7

Fixed with r4185

Note: See TracTickets for help on using tickets.