Skip to content

Instantly share code, notes, and snippets.

@kommen
Created November 11, 2011 15:17
Show Gist options
  • Save kommen/1358237 to your computer and use it in GitHub Desktop.
Save kommen/1358237 to your computer and use it in GitHub Desktop.
EXC_BAD_ACCESS is _class_getName when throwing NSException with ARC enabled
Throwing an exception like this:
@throw [NSException exceptionWithName:@"Exception" reason:@"none" userInfo:nil];
in a method, and trying to catch it in a method up the stack, causes a EXC_BAD_ACCESS in:
#0 0x36221fd0 in _class_getName ()
#1 0x36221fbc in object_getClassName ()
#2 0x362261fe in objc_exception_throw ()
But only on an iOS device.
The exact same code works as expected without a crash on the simulator.
Workarounds:
* Use CFBridgingRetain() on the exception (shown in the example project)
* or store the exception to a local variable first and then throw it
Filed as rdar://10330762
@kommen
Copy link
Author

kommen commented Jan 23, 2012

@tylercollier: Yeah, so it looks like Apple fixed that then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment