Objective-C iPhone 编程:尝试捕获异常
我使用 kumulos 来访问数据库。 这是我正在谈论的代码:
NSString *location = [[theResults objectAtIndex:0] objectForKey:@"location"];
现在如果 [theResults objectatindex:0] 返回“null”,它每次都会崩溃 因此,如果用户输入数据库中没有的内容,则会崩溃,我想捕获此异常(NSRange 异常)。
谢谢
im using kumulos to have access to a database.
this is the code i am talking about :
NSString *location = [[theResults objectAtIndex:0] objectForKey:@"location"];
Now the thing if [theResults objectatindex:0] return "null" it crash everytime
so if the user enter something that is not in the database it crash i want to catch this exeption (NSRange exeception).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这对你有用,不需要异常处理。
我假设
theResults
是一个NSArray
(或子类)。I think this will work for you without requiring exception handling.
I'm assuming that
theResults
is anNSArray
(or subclass).要么检查 [theResults objectAtIndex:0] 不返回 nil,要么使用异常处理,但
我建议至少学习一下该语言,或者使用 google 进行练习:-)
either you check that [theResults objectAtIndex:0] does not return nil, or you use exception handling
I would suggest to study the language at least a little bit, though, or practice with google :-)