@try { if(!self.usernameFIEld.text || [self.usernameFIEld.text isEqualToString:@""]) [NSException raise:@"InvalID value for username" format:@"Please enter your username."]; if(!self.passwordFIEld.text || [self.passwordFIEld.text isEqualToString:@""]) [NSException raise:@"InvalID value for password" format:@"Please enter your password."]; [LoginManager userLogin:self.usernameFIEld.text andPassword:self.passwordFIEld.text success:^(AFhttpRequestoperation *op,ID response) { if([self.delegate respondsToSelector:@selector(loginSuccessWithUsername:)]) { [self.delegate performSelector:@selector(loginSuccessWithUsername:)withObject:self.usernameFIEld.text]; } [self dismisspopoverController]; } failure:^(AFhttpRequestoperation *op,NSError *err) { Nsstring* nsLocalizedRecoverySuggestion = [err.userInfo objectForKey:@"NSLocalizedRecoverySuggestion"]; if(err.code == -1009) { [NSException raise:@"No Internet connection" format:@"It appears you’re not connected to the internet,please configure connectivity."]; } if([nsLocalizedRecoverySuggestion rangeOfString:@"Wrong username or password."].location != NSNotFound) { [NSException raise:@"InvalID username or password" format:@"Your given username or password is incorrect"]; } else { [NSException raise:@"BSXLoginVIEwController" format:@"Error during login"]; } }]; } @catch (NSException *exception) { UIAlertVIEw* alert = [[UIAlertVIEw alloc]initWithTitle:@"Login error" message:exception.description delegate:self cancelbuttonTitle:@"Ok" otherbuttonTitles:nil]; [alert show]; }
但是,在故障块中引发的异常不会在catch部分中被捕获.
我有点理解为什么它是合乎逻辑的,但是我想知道是否有办法告诉块我内部发生的异常应该由我创建的catch部分来处理.
谢谢你的帮助!
此致
佐利
但是,你在这里遇到了一个更大的问题,你正在进行的调用会阻止回调,因为它们会在完成之前返回.在这种情况下,在实际抛出异常之前很久就会退出异常处理程序.
在这种情况下,我建议删除异常并处理实际故障中的错误:通过调度到主队列并在那里呈现UIAlert来阻止.
总结以上是内存溢出为你收集整理的ios – Objective C – 从块内部引发的Catch异常全部内容,希望文章能够帮你解决ios – Objective C – 从块内部引发的Catch异常所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)