---
title: "NSException class of Foundation Framework"  
description: "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"  
author: "Tarun Kumar"  
published: 2015-10-24  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10968/nsexception-class-of-foundation-framework  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# NSException class of Foundation Framework

Cocoa’s '[exception handling](https://www.mindstick.com/articles/12240/introduction-of-exception-handling) system' handles the [exceptions](https://www.mindstick.com/interview/22871/define-predifined-generic-exceptions) whenever we create any product or app, it may be it produces errors that we call exceptions. The view of an [app crashes](https://www.mindstick.com/forum/159415/an-android-app-crashes-with-a-nullpointerexception) or freezes often during normal usage makes it poor.

The class used to [handle the exception](https://www.mindstick.com/forum/159349/who-and-how-handle-the-exception-when-we-use-throws) is NSException class. When any affected code raises a signal at the time of [compilation](https://www.mindstick.com/interview/358/which-is-the-first-level-of-compilation-in-the-dot-net-languages) 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](https://www.mindstick.com/forum/160424/how-do-bearer-tokens-ensure-the-security-and-confidentiality-of-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](https://www.mindstick.com/articles/157275/passed-peoplecert-it-infrastructure-library-itil-4-foundation-exam-today) 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](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties): name and reason both are NSString type and userInfo of type NSDictionary.

name property is the [unique ID](https://www.mindstick.com/forum/33873/how-to-get-unique-id-of-alasset-for-identification-in-ios) 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];
```

---

Original Source: https://www.mindstick.com/blog/10968/nsexception-class-of-foundation-framework

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
