@ try/@ catch不会捕获异常 [英] @try/@catch doesn't catch exception

查看:263
本文介绍了@ try/@ catch不会捕获异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Xcode从6.0升级到6.3后,我注意到我的自动化测试开始失败.

2015-04-14 18:56:50.625 xctest[48304:517820] *** Terminating app due to uncaught exception 'foo', reason: 'bar'
*** First throw call stack:
(
    0   CoreFoundation                      0x0084a746 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x004d3a97 objc_exception_throw + 44
    2   CoreFoundation                      0x0084a66d +[NSException raise:format:] + 141
    3   TestTests                           0x03e6dbdc -[TestTest test] + 810
    4   CoreFoundation                      0x0072b84d __invoking___ + 29
    5   CoreFoundation                      0x0072b6f8 -[NSInvocation invoke] + 360
    6   XCTest                              0x20108975 -[XCTestCase invokeTest] + 320
    7   XCTest                              0x20108baa -[XCTestCase performTest:] + 175
    8   XCTest                              0x20114122 -[XCTest run] + 314
    9   XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    10  XCTest                              0x20114122 -[XCTest run] + 314
    11  XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    12  XCTest                              0x20114122 -[XCTest run] + 314
    13  XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    14  XCTest                              0x20114122 -[XCTest run] + 314
    15  XCTest                              0x20103df2 __25-[XCTestDriver _runSuite]_block_invoke + 61
    16  XCTest                              0x20110c42 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 184
    17  XCTest                              0x20103d16 -[XCTestDriver _runSuite] + 285
    18  XCTest                              0x20104961 -[XCTestDriver _checkForTestManager] + 272
    19  XCTest                              0x20104c79 -[XCTestDriver runTestSuite:completionHandler:] + 376
    20  XCTest                              0x2011772c +[XCTestProbe runTests:] + 216
    21  libobjc.A.dylib                     0x004e967e +[NSObject performSelector:withObject:] + 70
    22  xctest                              0x0000823a xctest + 4666
    23  xctest                              0x000084b0 xctest + 5296
    24  xctest                              0x00008591 xctest + 5521
    25  xctest                              0x00007e3d xctest + 3645
    26  libdyld.dylib                       0x019d4ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

进一步调查后,发现现在无法捕获异常.这两个片段都会导致此错误.

XCTAssertThrows([NSException raise:@"foo" format:@"bar"]);

@try {
    [NSException raise:@"foo" format:@"bar"];
}
@catch (NSException *ex) {
    NSLog(@"caught");
}

在VCS强制执行干净同步和重建后,一切看起来都很好,但是随后的相同故障在几个构建时间内就开始了.有人有什么想法吗?

解决方案

在开发人员论坛之后,这似乎是开发人员工具中的错误或疏忽,引入了与使用较早版本的工具生成的二进制文件不兼容的功能.

应在Xcode 6.4中修复

After upgrading Xcode from 6.0 to 6.3, I noticed my automated tests started failing.

2015-04-14 18:56:50.625 xctest[48304:517820] *** Terminating app due to uncaught exception 'foo', reason: 'bar'
*** First throw call stack:
(
    0   CoreFoundation                      0x0084a746 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x004d3a97 objc_exception_throw + 44
    2   CoreFoundation                      0x0084a66d +[NSException raise:format:] + 141
    3   TestTests                           0x03e6dbdc -[TestTest test] + 810
    4   CoreFoundation                      0x0072b84d __invoking___ + 29
    5   CoreFoundation                      0x0072b6f8 -[NSInvocation invoke] + 360
    6   XCTest                              0x20108975 -[XCTestCase invokeTest] + 320
    7   XCTest                              0x20108baa -[XCTestCase performTest:] + 175
    8   XCTest                              0x20114122 -[XCTest run] + 314
    9   XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    10  XCTest                              0x20114122 -[XCTest run] + 314
    11  XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    12  XCTest                              0x20114122 -[XCTest run] + 314
    13  XCTest                              0x20107598 -[XCTestSuite performTest:] + 406
    14  XCTest                              0x20114122 -[XCTest run] + 314
    15  XCTest                              0x20103df2 __25-[XCTestDriver _runSuite]_block_invoke + 61
    16  XCTest                              0x20110c42 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 184
    17  XCTest                              0x20103d16 -[XCTestDriver _runSuite] + 285
    18  XCTest                              0x20104961 -[XCTestDriver _checkForTestManager] + 272
    19  XCTest                              0x20104c79 -[XCTestDriver runTestSuite:completionHandler:] + 376
    20  XCTest                              0x2011772c +[XCTestProbe runTests:] + 216
    21  libobjc.A.dylib                     0x004e967e +[NSObject performSelector:withObject:] + 70
    22  xctest                              0x0000823a xctest + 4666
    23  xctest                              0x000084b0 xctest + 5296
    24  xctest                              0x00008591 xctest + 5521
    25  xctest                              0x00007e3d xctest + 3645
    26  libdyld.dylib                       0x019d4ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

After further investigation it appears exceptions are now uncatchable. Both these snippets would cause this error.

XCTAssertThrows([NSException raise:@"foo" format:@"bar"]);

and

@try {
    [NSException raise:@"foo" format:@"bar"];
}
@catch (NSException *ex) {
    NSLog(@"caught");
}

After a VCS force clean sync and rebuild everything looked fine, but then the same failure started in a couple of builds time. Does anyone have any ideas?

解决方案

Following the developer forums, this appears to be a bug or oversight in the developer tools that introduced an incompatibility with binaries built with older versions of the tools.

Should be fixed in Xcode 6.4

这篇关于@ try/@ catch不会捕获异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆