mac*_*v30 14 exception objective-c ios
我们正在编写静态库.我们已经为暴露的API做了异常处理.但仍有少数未处理的异常(或操作系统异常).你能否告诉我如何捕捉这些未经处理的例外情况.谢谢
Fai*_* S. 11
那么,你总是可以依靠Catch'em All Principle
对于这类问题,我总是使用以下代码:
@try {
// do something
}
@catch (NSException *exception) {
// error happened! do something about the error state
}
@finally {
// do something to keep the program still running properly
}
Run Code Online (Sandbox Code Playgroud)
您可以使用NSSetUncaughtExceptionHandler
,您可能应该将其添加到AppDelegate
您可以在此页面上找到示例:http://www.learn-cocos2d.com/tag/nssetuncaughtexceptionhandler/
简单的 -
@try
{
//your code
}
@catch (NSException *theException)
{
NSLog(@"Exception: %@", theException);
}
Run Code Online (Sandbox Code Playgroud)
快乐编码...
归档时间: |
|
查看次数: |
18134 次 |
最近记录: |