NSException and Nserror

Source: Internet
Author: User
NSException and Nserror

Many languages throw all unintended (unexpected) errors as exceptions, but objective-c exceptions are only used to handle program errors. When an exception is thrown, the details are encapsulated in the NSException object. This information is primarily used to help programmers debug code, such as "attempting to access a seventh object in an array of only two objects." The NSException also includes the method call stack information, indicating the location of the code that throws the exception.
NSException and Nserror have different usage scenarios. If you need to indicate a programmer's coding error, you should use NSException. For example, a method can only accept an odd number as an argument, but the programmer passes an even number when calling the method, and an exception should be thrown to facilitate the programmer to resolve the code error. Conversely, for expected (expected) errors, such as user errors and device environment errors, you should use Nserror. For example, a method needs to read a user's photo, but does not have access to the user's album, and should return a Nserror object to the method caller indicating why the operation could not be performed.

NSException and Nserror

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.