]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-exception.h
objc4-723.tar.gz
[apple/objc4.git] / runtime / objc-exception.h
1 /*
2 * Copyright (c) 2002-2003, 2006-2007 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef __OBJC_EXCEPTION_H_
25 #define __OBJC_EXCEPTION_H_
26
27 #include <objc/objc.h>
28 #include <stdint.h>
29
30 #if !__OBJC2__
31
32 // compiler reserves a setjmp buffer + 4 words as localExceptionData
33
34 OBJC_EXPORT void
35 objc_exception_throw(id _Nonnull exception)
36 __OSX_AVAILABLE(10.3)
37 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
38 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
39
40 OBJC_EXPORT void
41 objc_exception_try_enter(void * _Nonnull localExceptionData)
42 __OSX_AVAILABLE(10.3)
43 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
44 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
45
46 OBJC_EXPORT void
47 objc_exception_try_exit(void * _Nonnull localExceptionData)
48 __OSX_AVAILABLE(10.3)
49 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
50 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
51
52 OBJC_EXPORT id _Nonnull
53 objc_exception_extract(void * _Nonnull localExceptionData)
54 __OSX_AVAILABLE(10.3)
55 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
56 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
57
58 OBJC_EXPORT int objc_exception_match(Class _Nonnull exceptionClass,
59 id _Nonnull exception)
60 __OSX_AVAILABLE(10.3)
61 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
62 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
63
64
65 typedef struct {
66 int version;
67 void (* _Nonnull throw_exc)(id _Nonnull); // version 0
68 void (* _Nonnull try_enter)(void * _Nonnull); // version 0
69 void (* _Nonnull try_exit)(void * _Nonnull); // version 0
70 id _Nonnull (* _Nonnull extract)(void * _Nonnull); // version 0
71 int (* _Nonnull match)(Class _Nonnull, id _Nonnull); // version 0
72 } objc_exception_functions_t;
73
74 // get table; version tells how many
75 OBJC_EXPORT void
76 objc_exception_get_functions(objc_exception_functions_t * _Nullable table)
77 __OSX_AVAILABLE(10.3)
78 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
79 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
80
81 // set table
82 OBJC_EXPORT void
83 objc_exception_set_functions(objc_exception_functions_t * _Nullable table)
84 __OSX_AVAILABLE(10.3)
85 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
86 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
87
88
89 // !__OBJC2__
90 #else
91 // __OBJC2__
92
93 typedef id _Nonnull (*objc_exception_preprocessor)(id _Nonnull exception);
94 typedef int (*objc_exception_matcher)(Class _Nonnull catch_type,
95 id _Nonnull exception);
96 typedef void (*objc_uncaught_exception_handler)(id _Null_unspecified /* _Nonnull */ exception);
97 typedef void (*objc_exception_handler)(id _Nullable unused,
98 void * _Nullable context);
99
100 /**
101 * Throw a runtime exception. This function is inserted by the compiler
102 * where \c @throw would otherwise be.
103 *
104 * @param exception The exception to be thrown.
105 */
106 OBJC_EXPORT void
107 objc_exception_throw(id _Nonnull exception)
108 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
109
110 OBJC_EXPORT void
111 objc_exception_rethrow(void)
112 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
113
114 OBJC_EXPORT id _Nonnull
115 objc_begin_catch(void * _Nonnull exc_buf)
116 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
117
118 OBJC_EXPORT void
119 objc_end_catch(void)
120 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
121
122 OBJC_EXPORT void
123 objc_terminate(void)
124 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
125
126 OBJC_EXPORT objc_exception_preprocessor _Nonnull
127 objc_setExceptionPreprocessor(objc_exception_preprocessor _Nonnull fn)
128 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
129
130 OBJC_EXPORT objc_exception_matcher _Nonnull
131 objc_setExceptionMatcher(objc_exception_matcher _Nonnull fn)
132 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
133
134 OBJC_EXPORT objc_uncaught_exception_handler _Nonnull
135 objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler _Nonnull fn)
136 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
137
138 // Not for iOS.
139 OBJC_EXPORT uintptr_t
140 objc_addExceptionHandler(objc_exception_handler _Nonnull fn,
141 void * _Nullable context)
142 __OSX_AVAILABLE(10.5)
143 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
144 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
145
146 OBJC_EXPORT void
147 objc_removeExceptionHandler(uintptr_t token)
148 __OSX_AVAILABLE(10.5)
149 __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
150 __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
151
152 // __OBJC2__
153 #endif
154
155 #endif // __OBJC_EXCEPTION_H_
156