]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-exception.h
objc4-779.1.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 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
37
38 OBJC_EXPORT void
39 objc_exception_try_enter(void * _Nonnull localExceptionData)
40 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
41
42 OBJC_EXPORT void
43 objc_exception_try_exit(void * _Nonnull localExceptionData)
44 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
45
46 OBJC_EXPORT id _Nonnull
47 objc_exception_extract(void * _Nonnull localExceptionData)
48 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
49
50 OBJC_EXPORT int objc_exception_match(Class _Nonnull exceptionClass,
51 id _Nonnull exception)
52 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
53
54
55 typedef struct {
56 int version;
57 void (* _Nonnull throw_exc)(id _Nonnull); // version 0
58 void (* _Nonnull try_enter)(void * _Nonnull); // version 0
59 void (* _Nonnull try_exit)(void * _Nonnull); // version 0
60 id _Nonnull (* _Nonnull extract)(void * _Nonnull); // version 0
61 int (* _Nonnull match)(Class _Nonnull, id _Nonnull); // version 0
62 } objc_exception_functions_t;
63
64 // get table; version tells how many
65 OBJC_EXPORT void
66 objc_exception_get_functions(objc_exception_functions_t * _Nullable table)
67 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
68
69 // set table
70 OBJC_EXPORT void
71 objc_exception_set_functions(objc_exception_functions_t * _Nullable table)
72 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
73
74
75 // !__OBJC2__
76 #else
77 // __OBJC2__
78
79 typedef id _Nonnull (*objc_exception_preprocessor)(id _Nonnull exception);
80 typedef int (*objc_exception_matcher)(Class _Nonnull catch_type,
81 id _Nonnull exception);
82 typedef void (*objc_uncaught_exception_handler)(id _Null_unspecified /* _Nonnull */ exception);
83 typedef void (*objc_exception_handler)(id _Nullable unused,
84 void * _Nullable context);
85
86 /**
87 * Throw a runtime exception. This function is inserted by the compiler
88 * where \c @throw would otherwise be.
89 *
90 * @param exception The exception to be thrown.
91 */
92 OBJC_EXPORT void
93 objc_exception_throw(id _Nonnull exception)
94 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
95
96 OBJC_EXPORT void
97 objc_exception_rethrow(void)
98 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
99
100 OBJC_EXPORT id _Nonnull
101 objc_begin_catch(void * _Nonnull exc_buf)
102 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
103
104 OBJC_EXPORT void
105 objc_end_catch(void)
106 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
107
108 OBJC_EXPORT void
109 objc_terminate(void)
110 OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
111
112 OBJC_EXPORT objc_exception_preprocessor _Nonnull
113 objc_setExceptionPreprocessor(objc_exception_preprocessor _Nonnull fn)
114 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
115
116 OBJC_EXPORT objc_exception_matcher _Nonnull
117 objc_setExceptionMatcher(objc_exception_matcher _Nonnull fn)
118 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
119
120 OBJC_EXPORT objc_uncaught_exception_handler _Nonnull
121 objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler _Nonnull fn)
122 OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
123
124 // Not for iOS.
125 OBJC_EXPORT uintptr_t
126 objc_addExceptionHandler(objc_exception_handler _Nonnull fn,
127 void * _Nullable context)
128 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.5);
129
130 OBJC_EXPORT void
131 objc_removeExceptionHandler(uintptr_t token)
132 OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.5);
133
134 // __OBJC2__
135 #endif
136
137 #endif // __OBJC_EXCEPTION_H_
138