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