Class

NSException

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

Declaration

class 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

class func raise(NSExceptionName, format: String, arguments: CVaListPointer)

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

init(name: NSExceptionName, reason: String?, userInfo: [AnyHashable : Any]?)

Initializes and returns a newly allocated exception object.

func raise()

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

Querying an NSException Object

var name: NSExceptionName

A string used to uniquely identify the receiver.

var reason: String?

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

var userInfo: [AnyHashable : Any]?

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

Getting Exception Stack Frames

var callStackReturnAddresses: [NSNumber]

The call return addresses related to a raised exception.

var callStackSymbols: [String]

An array containing the current call stack symbols.

Relationships

Inherits From

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software