When I run this code inside a call made from SenTest's STAssertThrowsSpecificNamed
:
@throw [[NSException alloc] initWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil];
I get (with NSZombieEnabled=YES
):
*** -[NSException reason]: message sent to deallocated instance 0x100a81d60
The exception is somehow deallocated before STAssertThrowsSpecificNamed
has finished processing it.
I can avoid the error by replacing the @throw
line above with this code:
NSException *exception = [NSException exceptionWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil];
@throw exception;
I get exactly the same behavior with or without ARC. Without ARC this code avoids the error too:
@throw [[[NSException alloc] initWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil] retain];
Is this a bug in SenTest? Or a bug in the compiler? Or is my first @throw
just incorrect?
I'm now exclusively using +[NSException raise:format:]
under both ARC and manual retain–release.