Objective-c Study Notes-Part 11-error handling

Source: Internet
Author: User

Object-C provides a Java/C ++-style error handling model. When the-fobjc-exceptions switch (GCC> 3.3) is used, it can work, however, this feature is only available in Versions later than OS X v10.3.

The principle of using error capture is similar to that of other languages: you cannot use it as a condition for normal stream processing. Instead, you can use it as an "unexpected"

You can use multiple @ catch blocks to capture different error types.

Cup * Cup = [[cup alloc] init];
 
@ Try {
[Cup fill];
}
@ Catch (nsexception * exception ){
Nslog (@ "Main: Caught % @: % @", [Exception name], [Exception reason]);
}
@ Finally {
[Cup release];
}

An exception class can be implemented by yourself, but it is generally nsexception or its subclass.

For more information about error handling, see:
Http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40001806

Related Article

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.