148fb7bfaSmrg /* GNU Objective C Runtime native exceptions 2*b1e83836Smrg Copyright (C) 2010-2022 Free Software Foundation, Inc. 348fb7bfaSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com> 448fb7bfaSmrg 548fb7bfaSmrg This file is part of GCC. 648fb7bfaSmrg 748fb7bfaSmrg GCC is free software; you can redistribute it and/or modify 848fb7bfaSmrg it under the terms of the GNU General Public License as published by 948fb7bfaSmrg the Free Software Foundation; either version 3, or (at your option) 1048fb7bfaSmrg any later version. 1148fb7bfaSmrg 1248fb7bfaSmrg GCC is distributed in the hope that it will be useful, 1348fb7bfaSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of 1448fb7bfaSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1548fb7bfaSmrg GNU General Public License for more details. 1648fb7bfaSmrg 1748fb7bfaSmrg Under Section 7 of GPL version 3, you are granted additional 1848fb7bfaSmrg permissions described in the GCC Runtime Library Exception, version 1948fb7bfaSmrg 3.1, as published by the Free Software Foundation. 2048fb7bfaSmrg 2148fb7bfaSmrg You should have received a copy of the GNU General Public License and 2248fb7bfaSmrg a copy of the GCC Runtime Library Exception along with this program; 2348fb7bfaSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2448fb7bfaSmrg <http://www.gnu.org/licenses/>. */ 2548fb7bfaSmrg 2648fb7bfaSmrg #ifndef __objc_exception_INCLUDE_GNU 2748fb7bfaSmrg #define __objc_exception_INCLUDE_GNU 2848fb7bfaSmrg 2948fb7bfaSmrg #include "objc.h" 3048fb7bfaSmrg #include "objc-decls.h" 3148fb7bfaSmrg 3248fb7bfaSmrg #ifdef __cplusplus 3348fb7bfaSmrg extern "C" { 3448fb7bfaSmrg #endif 3548fb7bfaSmrg 3648fb7bfaSmrg /* 'objc_exception_throw' throws the exception 'exception', which is 3748fb7bfaSmrg an exception object. 3848fb7bfaSmrg 3948fb7bfaSmrg Calls to 'objc_exception_throw' are automatically generated by the 4048fb7bfaSmrg compiler: an Objective-C "@throw exception;" statement gets 4148fb7bfaSmrg compiled into the equivalent of "objc_exception_throw 4248fb7bfaSmrg (exception);". 4348fb7bfaSmrg 4448fb7bfaSmrg 'objc_exception_throw' searches for a @catch() that can catch the 4548fb7bfaSmrg exception. By default, @catch (MyClass object) will catch all 4648fb7bfaSmrg exception objects that are of class MyClass or of a subclass of 4748fb7bfaSmrg MyClass; if the exception object is 'nil', then the exception can 4848fb7bfaSmrg only be caught with a catch-all exception handler where no 4948fb7bfaSmrg exception class is specified (such as @catch(id object)). This 5048fb7bfaSmrg behaviour can be customized by setting an 'objc_exception_matcher' 5148fb7bfaSmrg function (using objc_set_exception_matcher(), see below); if one is 5248fb7bfaSmrg set, it is used instead of the default one. 5348fb7bfaSmrg 5448fb7bfaSmrg If the exception is uncaught (there is no @catch() to catch it), 5548fb7bfaSmrg the program aborts. It is possible to customize this behaviour by 5648fb7bfaSmrg setting an 'objc_uncaught_exception_handler' function (using 5748fb7bfaSmrg objc_set_uncaught_exception_handler(), see below); if one is set, 5848fb7bfaSmrg it is executed before abort() is called. An uncaught exception 5948fb7bfaSmrg handler is expected to never return. */ 6048fb7bfaSmrg objc_EXPORT void objc_exception_throw (id exception); 6148fb7bfaSmrg 6248fb7bfaSmrg /* Compatibility note: the Apple/NeXT runtime seems to also have 6348fb7bfaSmrg objc_exception_rethrow(), objc_begin_catch() and objc_end_catch(). 6448fb7bfaSmrg Currently the GNU runtime does not use them. */ 6548fb7bfaSmrg 6648fb7bfaSmrg /* The following functions allow customizing to a certain extent the 6748fb7bfaSmrg exception handling. They are not thread safe and should be called 6848fb7bfaSmrg during the program initialization before threads are started. They 6948fb7bfaSmrg are mostly reserved for "Foundation" libraries; in the case of 7048fb7bfaSmrg GNUstep, GNUstep Base may be using these functions to improve the 7148fb7bfaSmrg standard exception handling. You probably shouldn't use these 7248fb7bfaSmrg functions unless you are writing your own Foundation library. */ 7348fb7bfaSmrg 7448fb7bfaSmrg /* Compatibility note: objc_set_exception_preprocessor() (available on 7548fb7bfaSmrg the Apple/NeXT runtime) is not available on the GNU runtime. */ 7648fb7bfaSmrg 7748fb7bfaSmrg /* An 'objc_exception_matcher' function is used to match an exception 7848fb7bfaSmrg to a @catch clause. 'catch_class' is the class of objects caught 7948fb7bfaSmrg by the @catch clause (for example, in "@catch (Object *o)", the 8048fb7bfaSmrg catch_class is Object). It should return 1 if the exception should 8148fb7bfaSmrg be caught by a @catch with a catch_class argument, and 0 if 8248fb7bfaSmrg not. */ 8348fb7bfaSmrg typedef int (*objc_exception_matcher)(Class catch_class, id exception); 8448fb7bfaSmrg 8548fb7bfaSmrg /* Sets a new exception matcher function, and returns the previous 8648fb7bfaSmrg exception matcher function. This function is not safe to call in a 8748fb7bfaSmrg multi-threaded environment because other threads may be trying to 8848fb7bfaSmrg invoke the exception matcher while you change it! */ 8948fb7bfaSmrg objc_EXPORT objc_exception_matcher 9048fb7bfaSmrg objc_setExceptionMatcher (objc_exception_matcher new_matcher); 9148fb7bfaSmrg 9248fb7bfaSmrg 9348fb7bfaSmrg /* An 'objc_uncaught_exception_handler' function is a function that 9448fb7bfaSmrg handles uncaught exceptions. It should never return. */ 9548fb7bfaSmrg typedef void (*objc_uncaught_exception_handler)(id exception); 9648fb7bfaSmrg 9748fb7bfaSmrg /* Sets a new uncaught exception handler function, and returns the 9848fb7bfaSmrg previous exception handler function. This function is not safe to 9948fb7bfaSmrg call in a multi-threaded environment because other threads may be 10048fb7bfaSmrg trying to invoke the uncaught exception handler while you change 10148fb7bfaSmrg it. */ 10248fb7bfaSmrg objc_EXPORT objc_uncaught_exception_handler 10348fb7bfaSmrg objc_setUncaughtExceptionHandler (objc_uncaught_exception_handler new_handler); 10448fb7bfaSmrg 10548fb7bfaSmrg #ifdef __cplusplus 10648fb7bfaSmrg } 10748fb7bfaSmrg #endif 10848fb7bfaSmrg 10948fb7bfaSmrg #endif /* not __objc_exception_INCLUDE_GNU */ 110