136ac495dSmrg /* GNU Objective C Runtime native exceptions 2*8feb0f0bSmrg Copyright (C) 2010-2020 Free Software Foundation, Inc. 336ac495dSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com> 436ac495dSmrg 536ac495dSmrg This file is part of GCC. 636ac495dSmrg 736ac495dSmrg GCC is free software; you can redistribute it and/or modify 836ac495dSmrg it under the terms of the GNU General Public License as published by 936ac495dSmrg the Free Software Foundation; either version 3, or (at your option) 1036ac495dSmrg any later version. 1136ac495dSmrg 1236ac495dSmrg GCC is distributed in the hope that it will be useful, 1336ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of 1436ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1536ac495dSmrg GNU General Public License for more details. 1636ac495dSmrg 1736ac495dSmrg Under Section 7 of GPL version 3, you are granted additional 1836ac495dSmrg permissions described in the GCC Runtime Library Exception, version 1936ac495dSmrg 3.1, as published by the Free Software Foundation. 2036ac495dSmrg 2136ac495dSmrg You should have received a copy of the GNU General Public License and 2236ac495dSmrg a copy of the GCC Runtime Library Exception along with this program; 2336ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2436ac495dSmrg <http://www.gnu.org/licenses/>. */ 2536ac495dSmrg 2636ac495dSmrg #ifndef __objc_exception_INCLUDE_GNU 2736ac495dSmrg #define __objc_exception_INCLUDE_GNU 2836ac495dSmrg 2936ac495dSmrg #include "objc.h" 3036ac495dSmrg #include "objc-decls.h" 3136ac495dSmrg 3236ac495dSmrg #ifdef __cplusplus 3336ac495dSmrg extern "C" { 3436ac495dSmrg #endif 3536ac495dSmrg 3636ac495dSmrg /* 'objc_exception_throw' throws the exception 'exception', which is 3736ac495dSmrg an exception object. 3836ac495dSmrg 3936ac495dSmrg Calls to 'objc_exception_throw' are automatically generated by the 4036ac495dSmrg compiler: an Objective-C "@throw exception;" statement gets 4136ac495dSmrg compiled into the equivalent of "objc_exception_throw 4236ac495dSmrg (exception);". 4336ac495dSmrg 4436ac495dSmrg 'objc_exception_throw' searches for a @catch() that can catch the 4536ac495dSmrg exception. By default, @catch (MyClass object) will catch all 4636ac495dSmrg exception objects that are of class MyClass or of a subclass of 4736ac495dSmrg MyClass; if the exception object is 'nil', then the exception can 4836ac495dSmrg only be caught with a catch-all exception handler where no 4936ac495dSmrg exception class is specified (such as @catch(id object)). This 5036ac495dSmrg behaviour can be customized by setting an 'objc_exception_matcher' 5136ac495dSmrg function (using objc_set_exception_matcher(), see below); if one is 5236ac495dSmrg set, it is used instead of the default one. 5336ac495dSmrg 5436ac495dSmrg If the exception is uncaught (there is no @catch() to catch it), 5536ac495dSmrg the program aborts. It is possible to customize this behaviour by 5636ac495dSmrg setting an 'objc_uncaught_exception_handler' function (using 5736ac495dSmrg objc_set_uncaught_exception_handler(), see below); if one is set, 5836ac495dSmrg it is executed before abort() is called. An uncaught exception 5936ac495dSmrg handler is expected to never return. */ 6036ac495dSmrg objc_EXPORT void objc_exception_throw (id exception); 6136ac495dSmrg 6236ac495dSmrg /* Compatibility note: the Apple/NeXT runtime seems to also have 6336ac495dSmrg objc_exception_rethrow(), objc_begin_catch() and objc_end_catch(). 6436ac495dSmrg Currently the GNU runtime does not use them. */ 6536ac495dSmrg 6636ac495dSmrg /* The following functions allow customizing to a certain extent the 6736ac495dSmrg exception handling. They are not thread safe and should be called 6836ac495dSmrg during the program initialization before threads are started. They 6936ac495dSmrg are mostly reserved for "Foundation" libraries; in the case of 7036ac495dSmrg GNUstep, GNUstep Base may be using these functions to improve the 7136ac495dSmrg standard exception handling. You probably shouldn't use these 7236ac495dSmrg functions unless you are writing your own Foundation library. */ 7336ac495dSmrg 7436ac495dSmrg /* Compatibility note: objc_set_exception_preprocessor() (available on 7536ac495dSmrg the Apple/NeXT runtime) is not available on the GNU runtime. */ 7636ac495dSmrg 7736ac495dSmrg /* An 'objc_exception_matcher' function is used to match an exception 7836ac495dSmrg to a @catch clause. 'catch_class' is the class of objects caught 7936ac495dSmrg by the @catch clause (for example, in "@catch (Object *o)", the 8036ac495dSmrg catch_class is Object). It should return 1 if the exception should 8136ac495dSmrg be caught by a @catch with a catch_class argument, and 0 if 8236ac495dSmrg not. */ 8336ac495dSmrg typedef int (*objc_exception_matcher)(Class catch_class, id exception); 8436ac495dSmrg 8536ac495dSmrg /* Sets a new exception matcher function, and returns the previous 8636ac495dSmrg exception matcher function. This function is not safe to call in a 8736ac495dSmrg multi-threaded environment because other threads may be trying to 8836ac495dSmrg invoke the exception matcher while you change it! */ 8936ac495dSmrg objc_EXPORT objc_exception_matcher 9036ac495dSmrg objc_setExceptionMatcher (objc_exception_matcher new_matcher); 9136ac495dSmrg 9236ac495dSmrg 9336ac495dSmrg /* An 'objc_uncaught_exception_handler' function is a function that 9436ac495dSmrg handles uncaught exceptions. It should never return. */ 9536ac495dSmrg typedef void (*objc_uncaught_exception_handler)(id exception); 9636ac495dSmrg 9736ac495dSmrg /* Sets a new uncaught exception handler function, and returns the 9836ac495dSmrg previous exception handler function. This function is not safe to 9936ac495dSmrg call in a multi-threaded environment because other threads may be 10036ac495dSmrg trying to invoke the uncaught exception handler while you change 10136ac495dSmrg it. */ 10236ac495dSmrg objc_EXPORT objc_uncaught_exception_handler 10336ac495dSmrg objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler new_handler); 10436ac495dSmrg 10536ac495dSmrg #ifdef __cplusplus 10636ac495dSmrg } 10736ac495dSmrg #endif 10836ac495dSmrg 10936ac495dSmrg #endif /* not __objc_exception_INCLUDE_GNU */ 110