ios - objective-c 没有在 try/catch block 中捕获异常

标签 ios objective-c exception try-catch

我在 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设置。

我把它去掉,问题就解决了。

Pic

关于ios - objective-c 没有在 try/catch block 中捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35939491/

相关文章:

java - 我们是否需要声明方法可以抛出的未经检查的异常?

ios - 使用 TM-T81 epson iOS SDK 打开钱箱

c# - 从 IntPtr 创建 NSException

ios - AFNetworking 返回函数

objective-c - NSPersistentDocument "Unsupported store type"异常

ios - 从 Apple Watch 扬声器播放声音

java - 切换按钮分配 double 值时出现致命异常 : java. lang.NumberFormatException

Java:掉落到下一个 `catch` 子句

ios - 由于 Yoga 错误,React Native iOS 构建失败

iphone - iOS 5.0 检测应用程序何时从 Safari.app 中的 URL 重新激活