在ios开发中使用 try 和 catch 来捕获错误。
2012-06-28 15:11
375 查看
转载自:http://blog.csdn.net/remote_roamer/article/details/7105776
抛出错误的代码
[cpp] view
plaincopy
//如果返回的报文是错误信息,则抛出错误
if([outParams count] <= 0)
{
[NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];
}
在调用中捕获错误代码
[cpp] view
plaincopy
//从soap 信息中解析出CusotmerDetail 对象
@try
{
customerDetail = [[[SoapRtnJsonParser alloc] init] parse2CustomerDtail:[returnSoapXML dataUsingEncoding:NSUTF8StringEncoding]];
}@catch (NSException * e) {
NSLog(@"Exception: %@", e);
UIAlertView * alert =
[[UIAlertView alloc]
initWithTitle:@"错误"
message: [[NSString alloc] initWithFormat:@"%@",e]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return;
}
抛出错误的代码
[cpp] view
plaincopy
//如果返回的报文是错误信息,则抛出错误
if([outParams count] <= 0)
{
[NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];
}
在调用中捕获错误代码
[cpp] view
plaincopy
//从soap 信息中解析出CusotmerDetail 对象
@try
{
customerDetail = [[[SoapRtnJsonParser alloc] init] parse2CustomerDtail:[returnSoapXML dataUsingEncoding:NSUTF8StringEncoding]];
}@catch (NSException * e) {
NSLog(@"Exception: %@", e);
UIAlertView * alert =
[[UIAlertView alloc]
initWithTitle:@"错误"
message: [[NSString alloc] initWithFormat:@"%@",e]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return;
}
相关文章推荐
- IOS开发之--异常处理--使用try 和 catch 来捕获错误。
- 在ios开发中使用 try 和 catch 来捕获错误。
- 在ios开发中使用 try 和 catch 来捕获错误。
- 在ios开发中使用 try 和 catch 来捕获错误。
- 在ios开发中使用 try 和 catch 来捕获错误。
- iOS中try-catch-finally捕获异常使用
- iOS中@try@catch@finally捕获异常使用
- 后台判断格式是否想要的类型可使用 try{} catch{}捕获错误,
- iOS中@try@catch@finally捕获异常使用
- iOS开发过程中使用Core Data应避免的十个错误
- 使用try...catch...and or....finally (vbscript or jscript) 处理可能的某些或全部错误
- 使用lua实现try-catch异常捕获
- iOS开发过程中使用Core Data应避免的十个错误
- sql语句trycatch捕获错误信息
- iOS - try~catch捕获异常防止崩溃简单实用
- 【工控机开发】linux下错误的捕获:errno和strerror的使用
- Android开发如何使用UncaughtExceptionHandler捕获程序崩溃错误信息?
- Foreach语句,Throw语句,Try,catch语句的使用,报告编译错误
- js错误处理try..catch使用
- ios定位开发 当使用百度地图sdk没有启用object c++混编时就会出现如下错误