iphone os 框架本身会抛出 NSException 吗?

发布于 2024-09-26 21:28:30 字数 129 浏览 0 评论 0原文

我知道我可以在自己的代码中抛出 NSException,iphone os 框架本身会抛出 NSException 吗? 如果是这样,意味着我应该从框架捕获 NSExceptions? 我知道Java会在SDK内部抛出异常,例如未经检查的异常。

I know i can throw an NSException in my own code,does iphone os framework throw NSException itself?
if it does,means that i should catch the NSExceptions from framework?
I know Java throws Exceptions inner SDK,such as unchecked exceptions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦巷 2024-10-03 21:28:30

iOS 和 Cocoa 中的框架抛出的异常表明存在不可恢复的错误。不使用异常(除了非常极端的异常)来传达诸如验证问题之类的内容。

一般来说,iOS 和 Cocoa 使用 NSError 来传达可恢复的问题(例如用户输入验证错误、核心数据中的状态验证错误或连接问题)。

除了指示不可恢复的问题之外,您不应在自己的代码中使用异常。它违背了底层框架的模式,这样做将使您的代码更难以随着时间的推移而发展。

Exceptions thrown by the frameworks in iOS and Cocoa are indicative of unrecoverable errors. Exceptions are not used (outside of very extreme exceptions) to convey something like a validation problem.

In general, iOS and Cocoa use NSError to convey recoverable problems (like user entry validation errors, state validation errors in Core Data, or connectivity issues, for examples).

You should not use exceptions within your own code for purposes beyond indicating unrecoverable problems. It goes against the patterns of the underlying frameworks and doing so will make your code more difficult to evolve over time.

逆蝶 2024-10-03 21:28:30

您想在代码中抛出 NSException,并且想知道框架是否也抛出它们。好吧,如果发生错误,它就会抛出它们。您可以通过将每个抛出异常的代码放在 try...catch...finally 块中来捕获它们,该块与“您的”异常抛出代码的块不同:)也许其他人可以提供更多信息并希望我做对了你想做的事。

You want to throw NSExceptions in your code, and you want to know if the framework throws them too. Well, it throws them if an error occurs. You can catch them by putting each exception-throwing piece of code in a try... catch... finally block which is different from the one for "your" exception-throwing code :) Maybe others can offer more info and hope I got it right what you are trying to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文