Unable to catch NSException instances raised in a playground
Originator: | brian.s.croom | ||
Number: | rdar://25897711 | Date Originated: | 24-Apr-2016 04:29 PM |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | Xcode 7.3 |
Classification: | Reproducible: | 100% |
Summary: Normally it is possible to execute Swift code wrapped in an Objective-C function which can catch any NSException instances that get raised. However when importing such a wrapper function into a playground and using it there, an exception causes playground execution to immediately halt, rather than the exception being caught. Steps to Reproduce: 1. Open the ExceptionCatcher Xcode workspace from the attached file, or cloned from: https://github.com/briancroom/RadarSamples 2. Observe that the ExceptionCatcher.framework target exposes an Objective-C function which receives a block and executes it within an @try block, catching and logging any exceptions. 3. Execute the unit tests for the framework, demonstrating the expected behavior where thrown exceptions are properly caught. 4. Open and execute Playground.playground, which has the same client code as the unit tests Expected Results: An exception thrown in a closure passed to the `performBlockCatchingExceptions` function should be caught and logged, and playground execution should continue Actual Results: The exception causes playground execution to halt, and produces the following console output: 2016-04-24 16:20:13.697 Playground[10555:212120] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Boom' *** First throw call stack: ( 0 CoreFoundation 0x000000010fdaed85 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010f820deb objc_exception_throw + 48 2 CoreFoundation 0x000000010fdae9c9 -[NSException raise] + 9 3 ExceptionCatcher 0x000000011affa8fe _TF16ExceptionCatcher16throwAnExceptionFT_T_ + 174 4 ??? 0x000000011affe197 0x0 + 4747944343 5 ??? 0x000000011affe1de 0x0 + 4747944414 6 ExceptionCatcher 0x000000011affa7a1 performBlockCatchingExceptions + 49 7 ??? 0x000000011afe77e9 0x0 + 4747851753 8 Playground 0x000000010f2afab0 main + 0 9 Playground 0x000000010f2b29a1 _TTRXFo__dT__XFo_iT__iT__ + 17 10 Playground 0x000000010f2b2401 _TPA__TTRXFo__dT__XFo_iT__iT__ + 81 11 Playground 0x000000010f2b29d0 _TTRXFo_iT__iT__XFo__dT__ + 32 12 Playground 0x000000010f2b2a07 _TTRXFo__dT__XFdCb__dT__ + 39 13 CoreFoundation 0x000000010fcd42ec __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 14 CoreFoundation 0x000000010fcc9f75 __CFRunLoopDoBlocks + 341 15 CoreFoundation 0x000000010fcc96d2 __CFRunLoopRun + 850 16 CoreFoundation 0x000000010fcc90f8 CFRunLoopRunSpecific + 488 17 GraphicsServices 0x00000001168d8ad2 GSEventRunModal + 161 18 UIKit 0x0000000110165f09 UIApplicationMain + 171 19 Playground 0x000000010f2aff39 main + 1161 20 libdyld.dylib 0x0000000112b0c92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException Notes: This issue is preventing me from producing a playground that demonstrates the usage of an Objective-C framework
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!