我在 try/catch block 中有这个语句,但从未捕获到异常。事实上,任何抛出的异常都不会被捕获。 谁能帮帮我?
xcode项目中是否有禁用捕获异常的设置?
NSString *test = @"test";
unichar a;
int index = 5;
@try {
a = [test characterAtIndex:index];
}
@catch (NSException *exception) {
NSLog(@"%@", exception.reason);
}
@finally {
NSLog(@"Char at index %d cannot be found", index);
NSLog(@"Max index is: %lu", [test length]-1);
}
* Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds' * First throw call stack: (0x1832ad900 0x18291bf80 0x1832ad848 0x1831a52f0 0x100249340 0x188015704 0x188244130 0x1882484b8 0x1882455c0 0x184863790 0x184863b10 0x183264efc 0x183264990 0x183262690 0x183191680 0x18800e580 0x188008d90 0x10017662c 0x182d328b8) libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
在我的例子中,有一个 Other Liker Flag -Wl,-no_compact_unwind
我项目的build设置。
我把它去掉,问题就解决了。
关于ios - objective-c 没有在 try/catch block 中捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35939491/