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