blog

Home / DeveloperSection / Blogs / NSException class of Foundation Framework

NSException class of Foundation Framework

Tarun Kumar3058 24-Oct-2015

Cocoa’s 'exception handling system' handles the exceptions whenever we create any product or app, it may be it produces errors that we call exceptions. The view of an app crashes or freezes often during normal usage makes it poor.

The class used to handle the exception is NSException class. When any affected code raises a signal at the time of compilation known as an exception, and after those signals moves outwards until it reaches a code segment known as a handler. But if the signal reaches the topmost handler it becomes an uncaught exception. The topmost or default handler saves any user data and does any clean-up chores before it shuts down the app.

Now we see some points about NSException class:

 NSException class is a part of Foundation framework.

NSException class provides the methods that allow to create exception objects, and throw the exceptions with them and get the call return address related to an exception.

Its exception handler method:

[NSException exceptionWithName:@”name” reason:@”reason” userInfo:nil];

has three private properties: name and reason both are NSString type and userInfo of type NSDictionary.

name property is the unique ID of the exception and reason property contains more information about the exception.                                           

Example:

NSException *exceptionObj;

exceptionObj = [NSException  exceptionWithName:@”Testing”

                                                      reason:@”Testing for Exception”

                                                      userInfo:nil];


Updated 13-Mar-2018

Leave Comment

Comments

Liked By