objc-exception.h 4.7 KB

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