2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 This file defines the interface to the exception raising scheme.
31 Copyright (c) 1988-1996 NeXT Software, Inc. as an unpublished work.
35 #warning The API in this header is obsoleted by NSException et al.
37 #ifndef _OBJC_ERROR_H_
38 #define _OBJC_ERROR_H_
41 #import <objc/objc-api.h>
44 typedef struct _NXHandler
{ /* a node in the handler chain */
45 jmp_buf jumpState
; /* place to longjmp to */
46 struct _NXHandler
*next
; /* ptr to next handler */
47 int code
; /* error code of exception */
48 const void *data1
, *data2
; /* blind data for describing error */
52 /* Handles RAISE's with nowhere to longjmp to */
53 typedef void NXUncaughtExceptionHandler(int code
, const void *data1
,
55 OBJC_EXPORT NXUncaughtExceptionHandler
*_NXUncaughtExceptionHandler
;
56 #define NXGetUncaughtExceptionHandler() _NXUncaughtExceptionHandler
57 #define NXSetUncaughtExceptionHandler(proc) \
58 (_NXUncaughtExceptionHandler = (proc))
60 /* NX_DURING, NX_HANDLER and NX_ENDHANDLER are always used like:
63 some code which might raise an error
65 code that will be jumped to if an error occurs
68 If any error is raised within the first block of code, the second block
69 of code will be jumped to. Typically, this code will clean up any
70 resources allocated in the routine, possibly case on the error code
71 and perform special processing, and default to RERAISE the error to
72 the next handler. Within the scope of the handler, a local variable
73 called NXLocalHandler of type NXHandler holds information about the
76 It is illegal to exit the first block of code by any other means than
77 NX_VALRETURN, NX_VOIDRETURN, or just falling out the bottom.
80 /* private support routines. Do not call directly. */
81 OBJC_EXPORT
void _NXAddHandler( NXHandler
*handler
);
82 OBJC_EXPORT
void _NXRemoveHandler( NXHandler
*handler
);
84 #define NX_DURING { NXHandler NXLocalHandler; \
85 _NXAddHandler(&NXLocalHandler); \
86 if( !_setjmp(NXLocalHandler.jumpState) ) {
88 #define NX_HANDLER _NXRemoveHandler(&NXLocalHandler); } else {
90 #define NX_ENDHANDLER }}
92 #define NX_VALRETURN(val) do { typeof(val) temp = (val); \
93 _NXRemoveHandler(&NXLocalHandler); \
94 return(temp); } while (0)
96 #define NX_VOIDRETURN do { _NXRemoveHandler(&NXLocalHandler); \
99 /* RAISE and RERAISE are called to indicate an error condition. They
100 initiate the process of jumping up the chain of handlers.
104 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
105 volatile /* never returns */
107 void _NXRaiseError(int code
, const void *data1
, const void *data2
)
108 #if defined(__GNUC__)
109 __attribute__ ((noreturn
))
113 #define NX_RAISE( code, data1, data2 ) \
114 _NXRaiseError( (code), (data1), (data2) )
116 #define NX_RERAISE() _NXRaiseError( NXLocalHandler.code, \
117 NXLocalHandler.data1, NXLocalHandler.data2 )
119 /* These routines set and return the procedure which is called when
120 exceptions are raised. This procedure must NEVER return. It will
121 usually either longjmp, or call the uncaught exception handler.
122 The default exception raiser is also declared
124 typedef volatile void NXExceptionRaiser(int code
, const void *data1
, const void *data2
);
125 OBJC_EXPORT
void NXSetExceptionRaiser(NXExceptionRaiser
*proc
);
126 OBJC_EXPORT NXExceptionRaiser
*NXGetExceptionRaiser(void);
127 OBJC_EXPORT NXExceptionRaiser NXDefaultExceptionRaiser
;
130 /* The error buffer is used to allocate data which is passed up to other
131 handlers. Clients should clear the error buffer in their top level
132 handler. The Application Kit does this.
134 OBJC_EXPORT
void NXAllocErrorData(int size
, void **data
);
135 OBJC_EXPORT
void NXResetErrorData(void);
137 #endif /* _OBJC_ERROR_H_ */