在 xcode 中使用 try catch 块是否在真实设备上显示错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1312400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:45:07  来源:igfitidea点击:

does using try catch block in xcode show error on real device?

objective-ciphonexcodedebuggingjailbreak

提问by Rahul Vyas

my application is running fine in simulator...but not on real device....and i have jailbroken iphone so i am unable to debug through device...if i use try catch something like this

我的应用程序在模拟器中运行良好......但不是在真实设备上......而且我已经越狱了 iphone 所以我无法通过设备进行调试......如果我使用 try catch 这样的东西

@try
{
Statements
}

@catch (NSException *ex) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",ex]
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
}

will my application show error on alertview before crashing?

我的应用程序会在崩溃前在警报视图上显示错误吗?

if not how could i find where is the bug?

如果不是,我怎么能找到错误在哪里?

采纳答案by Daniel

Catching the exception means you are doing something in response to this "error" coming about and it wont crash the application , thats the point of catching exceptions-to tell how to handle cases where errors arrise so your app wont crash, so yes the alert view will show...

捕捉异常意味着你正在做一些事情来响应这个“错误”的发生,它不会使应用程序崩溃,这就是捕捉异常的重点——告诉如何处理出现错误的情况,这样你的应用程序就不会崩溃,所以是警报视图将显示...

回答by slf

That will work so long as your @catch block doesn't throw any exceptions while trying to build the UIAlertView. Make sure you releaseor autoreleaseit, and support the UIAlertViewDelegateprotocol.

只要您的 @catch 块在尝试构建UIAlertView. 确保您releaseautorelease它,并支持UIAlertViewDelegate协议。

回答by slf

Try this:

尝试这个:

UIAlertView *alert = [[UIAlertView alloc]
 initWithTitle:[ex name]
 message:[ex reason]
 delegate:self
 cancelButtonTitle:@"OK"
 otherButtonTitles: nil];