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
間違っていますか?