当我在 SenTest 的调用中运行此代码时STAssertThrowsSpecificNamed
:
@throw [[NSException alloc] initWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil];
我得到(带NSZombieEnabled=YES
):
*** -[NSException reason]: message sent to deallocated instance 0x100a81d60
异常在STAssertThrowsSpecificNamed
完成处理之前以某种方式被释放。
@throw
我可以通过用以下代码替换上面的行来避免错误:
NSException *exception = [NSException exceptionWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil];
@throw exception;
无论有没有ARC,我都会得到完全相同的行为。如果没有 ARC,此代码也可以避免错误:
@throw [[[NSException alloc] initWithName:NSInvalidArchiveOperationException
reason:@"---some reason----"
userInfo:nil] retain];
这是 SenTest 中的错误吗?还是编译器中的错误?还是我的第一个@throw
不正确?