fedor@boulder.colorado.edu
)Date: Generated at 2024-11-18 21:56:13 +0100
Copyright: (C) 1995, 1996 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSException.h
NSAssertionHandler objects are used to
raise exceptions on behalf of macros implementing
assertions.
Each thread has its own
assertion handler instance.
The macros work together with the assertion handler object to produce meaningful exception messages containing the name of the source file, the position within that file, and the name of the ObjC method or C function in which the assertion failed.
An NSAssertionHandler instance is created on demand for each thread and is stored in the thread's dictionary under the key NSAssertionHandler. A custom NSAssertionHandler can be used by adding it to the thread dictionary under this key.
The assertion macros are:
NSAssert()
, NSCAssert()
,
NSAssert1()
, NSCAssert1()
,
NSAssert2()
, NSCAssert2()
,
NSAssert3()
, NSCAssert3()
,
NSAssert4()
, NSCAssert4()
,
NSAssert5()
, NSCAssert5()
,
NSParameterAssert()
,
NSCParameterAssert()
The numbered macros arre obsolete, dating from
a time when
NSAssert()
and NSCAssert()
did not support a variable number of arguments.
- Declared in:
- Foundation/NSException.h
The NSException
class helps manage errors
in a program. It provides a mechanism for lower-level
methods to provide information about problems to
higher-level methods, which more often than
not, have a better ability to decide what to do about
the problems.
Exceptions are typically handled by enclosing a
sensitive section of code inside the macros
NS_DURING
and NS_HANDLER
,
and then handling any problems after this, up to the
NS_ENDHANDLER
macro:
NS_DURING code that might cause an exception NS_HANDLER code that deals with the exception. If this code cannot deal with it, you can re-raise the exception like this [localException raise] so the next higher level of code can handle it NS_ENDHANDLER
The local variable localException
is the
name of the exception object you can use in the
NS_HANDLER
section. The easiest way to
cause an exception is using the
+raise:format:,...
method.
If there is no NS_HANDLER... NS_ENDHANDLER block
enclosing (directly or indirectly) code where an
exception is raised, then control passes to the
uncaught exception handler function and the
program is then terminated.
The uncaught
exception handler is set using
NSSetUncaughtExceptionHandler()
and if not set, defaults to a function which will
simply print an error message before the program
terminates.