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

我在try / catch块中有这个语句,但是异常永远不会被捕获.实际上,抛出的任何异常都不会被捕获.

谁能帮我?

是否在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

最佳答案 就我而言,还有一个其他Liker Flag -Wl,-no_compact_unwind in

我的项目的构建设置.

我删除它,然后问题得到解决.

点赞