1 /* GNU Objective C Runtime native exceptions
2 Copyright (C) 2010 Free Software Foundation, Inc.
3 Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef __objc_exception_INCLUDE_GNU
27 #define __objc_exception_INCLUDE_GNU
35 /* 'objc_exception_throw' throws the exception 'exception', which is
38 Calls to 'objc_exception_throw' are automatically generated by the
39 compiler: an Objective-C "@throw exception;" statement gets
40 compiled into the equivalent of "objc_exception_throw
43 'objc_exception_throw' searches for a @catch() that can catch the
44 exception. By default, @catch (MyClass object) will catch all
45 exception objects that are of class MyClass or of a subclass of
46 MyClass; if the exception object is 'nil', then the exception can
47 only be caught with a catch-all exception handler where no
48 exception class is specified (such as @catch(id object)). This
49 behaviour can be customized by setting an 'objc_exception_matcher'
50 function (using objc_set_exception_matcher(), see below); if one is
51 set, it is used instead of the default one.
53 If the exception is uncaught (there is no @catch() to catch it),
54 the program aborts. It is possible to customize this behaviour by
55 setting an 'objc_uncaught_exception_handler' function (using
56 objc_set_uncaught_exception_handler(), see below); if one is set,
57 it is executed before abort() is called. An uncaught exception
58 handler is expected to never return.
60 void objc_exception_throw (id exception
);
62 /* Compatibility note: the Apple/NeXT runtime seems to also have
63 objc_exception_rethrow(), objc_begin_catch() and objc_end_catch().
64 Currently the GNU runtime does not use them.
67 /* The following functions allow customizing to a certain extent the
68 exception handling. They are not thread safe and should be called
69 during the program initialization before threads are started. They
70 are mostly reserved for "Foundation" libraries; in the case of
71 GNUstep, GNUstep Base may be using these functions to improve the
72 standard exception handling. You probably shouldn't use these
73 functions unless you are writing your own Foundation library.
76 /* Compatibility note: objc_set_exception_preprocessor() (available on
77 the Apple/NeXT runtime) is not available on the GNU runtime. */
79 /* An 'objc_exception_matcher' function is used to match an exception
80 to a @catch clause. 'catch_class' is the class of objects caught
81 by the @catch clause (for example, in "@catch (Object *o)", the
82 catch_class is Object). It should return 1 if the exception should
83 be caught by a @catch with a catch_class argument, and 0 if
85 typedef int (*objc_exception_matcher
)(Class catch_class
, id exception
);
87 /* Sets a new exception matcher function, and returns the previous
88 exception matcher function. This function is not safe to call in a
89 multi-threaded environment because other threads may be trying to
90 invoke the exception matcher while you change it! */
91 objc_exception_matcher
92 objc_setExceptionMatcher (objc_exception_matcher new_matcher
);
95 /* An 'objc_uncaught_exception_handler' function is a function that
96 handles uncaught exceptions. It should never return. */
97 typedef void (*objc_uncaught_exception_handler
)(id exception
);
99 /* Sets a new uncaught exception handler function, and returns the
100 previous exception handler function. This function is not safe to
101 call in a multi-threaded environment because other threads may be
102 trying to invoke the uncaught exception handler while you change
105 objc_uncaught_exception_handler
106 objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler new_handler
);
112 #endif /* not __objc_exception_INCLUDE_GNU */