Class

NSException

An object that represents a special condition that interrupts the normal flow of program execution.

Declaration

@interface NSException : NSObject

Overview

Use NSException to implement exception handling. An exception is a special condition that interrupts the normal flow of program execution. Each application can interrupt the program for different reasons. For example, one application might interpret saving a file in a directory that is write-protected as an exception. In this sense, the exception is equivalent to an error. Another application might interpret the user’s key-press (for example, Control-C) as an exception: an indication that a long-running process should abort.

Topics

Creating and Raising an NSException Object

+ exceptionWithName:reason:userInfo:

Creates and returns an exception object .

+ raise:format:

A convenience method that creates and raises an exception.

+ raise:format:arguments:

Creates and raises an exception with the specified name, reason, and arguments.

- initWithName:reason:userInfo:

Initializes and returns a newly allocated exception object.

- raise

Raises the receiver, causing program flow to jump to the local exception handler.

Querying an NSException Object

name

A string used to uniquely identify the receiver.

reason

A string containing a “human-readable” reason for the receiver.

userInfo

A dictionary containing application-specific data pertaining to the receiver.

Getting Exception Stack Frames

callStackReturnAddresses

The call return addresses related to a raised exception.

callStackSymbols

An array containing the current call stack symbols.

Functions

NSGetUncaughtExceptionHandler

Returns the top-level error handler.

NSSetUncaughtExceptionHandler

Changes the top-level error handler.

Legacy Macros

NS_DURING

Marks the start of the exception-handling domain.

NS_ENDHANDLER

Marks the end of the local event handler.

NS_HANDLER

Marks the end of the exception-handling domain and the start of the local exception handler.

NS_VALUERETURN

Permits program control to exit from an exception-handling domain with a value of a specified type.

NS_VOIDRETURN

Permits program control to exit from an exception-handling domain.

Relationships

Inherits From