objc-exception.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2002-2003, 2006-2007 Apple Inc. All Rights Reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apple Public Source License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://www.opensource.apple.com/apsl/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. *
  21. * @APPLE_LICENSE_HEADER_END@
  22. */
  23. #ifndef __OBJC_EXCEPTION_H_
  24. #define __OBJC_EXCEPTION_H_
  25. #include <objc/objc.h>
  26. #include <stdint.h>
  27. #if !__OBJC2__
  28. // compiler reserves a setjmp buffer + 4 words as localExceptionData
  29. OBJC_EXPORT void
  30. objc_exception_throw(id _Nonnull exception)
  31. __OSX_AVAILABLE(10.3)
  32. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  33. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  34. OBJC_EXPORT void
  35. objc_exception_try_enter(void * _Nonnull localExceptionData)
  36. __OSX_AVAILABLE(10.3)
  37. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  38. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  39. OBJC_EXPORT void
  40. objc_exception_try_exit(void * _Nonnull localExceptionData)
  41. __OSX_AVAILABLE(10.3)
  42. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  43. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  44. OBJC_EXPORT id _Nonnull
  45. objc_exception_extract(void * _Nonnull localExceptionData)
  46. __OSX_AVAILABLE(10.3)
  47. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  48. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  49. OBJC_EXPORT int objc_exception_match(Class _Nonnull exceptionClass,
  50. id _Nonnull exception)
  51. __OSX_AVAILABLE(10.3)
  52. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  53. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  54. typedef struct {
  55. int version;
  56. void (* _Nonnull throw_exc)(id _Nonnull); // version 0
  57. void (* _Nonnull try_enter)(void * _Nonnull); // version 0
  58. void (* _Nonnull try_exit)(void * _Nonnull); // version 0
  59. id _Nonnull (* _Nonnull extract)(void * _Nonnull); // version 0
  60. int (* _Nonnull match)(Class _Nonnull, id _Nonnull); // version 0
  61. } objc_exception_functions_t;
  62. // get table; version tells how many
  63. OBJC_EXPORT void
  64. objc_exception_get_functions(objc_exception_functions_t * _Nullable table)
  65. __OSX_AVAILABLE(10.3)
  66. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  67. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  68. // set table
  69. OBJC_EXPORT void
  70. objc_exception_set_functions(objc_exception_functions_t * _Nullable table)
  71. __OSX_AVAILABLE(10.3)
  72. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  73. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  74. // !__OBJC2__
  75. #else
  76. // __OBJC2__
  77. typedef id _Nonnull (*objc_exception_preprocessor)(id _Nonnull exception);
  78. typedef int (*objc_exception_matcher)(Class _Nonnull catch_type,
  79. id _Nonnull exception);
  80. typedef void (*objc_uncaught_exception_handler)(id _Null_unspecified /* _Nonnull */ exception);
  81. typedef void (*objc_exception_handler)(id _Nullable unused,
  82. void * _Nullable context);
  83. /**
  84. * Throw a runtime exception. This function is inserted by the compiler
  85. * where \c @throw would otherwise be.
  86. *
  87. * @param exception The exception to be thrown.
  88. */
  89. OBJC_EXPORT void
  90. objc_exception_throw(id _Nonnull exception)
  91. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  92. OBJC_EXPORT void
  93. objc_exception_rethrow(void)
  94. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  95. OBJC_EXPORT id _Nonnull
  96. objc_begin_catch(void * _Nonnull exc_buf)
  97. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  98. OBJC_EXPORT void
  99. objc_end_catch(void)
  100. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  101. OBJC_EXPORT void
  102. objc_terminate(void)
  103. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  104. OBJC_EXPORT objc_exception_preprocessor _Nonnull
  105. objc_setExceptionPreprocessor(objc_exception_preprocessor _Nonnull fn)
  106. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  107. OBJC_EXPORT objc_exception_matcher _Nonnull
  108. objc_setExceptionMatcher(objc_exception_matcher _Nonnull fn)
  109. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  110. OBJC_EXPORT objc_uncaught_exception_handler _Nonnull
  111. objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler _Nonnull fn)
  112. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  113. // Not for iOS.
  114. OBJC_EXPORT uintptr_t
  115. objc_addExceptionHandler(objc_exception_handler _Nonnull fn,
  116. void * _Nullable context)
  117. __OSX_AVAILABLE(10.5)
  118. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  119. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  120. OBJC_EXPORT void
  121. objc_removeExceptionHandler(uintptr_t token)
  122. __OSX_AVAILABLE(10.5)
  123. __IOS_UNAVAILABLE __TVOS_UNAVAILABLE
  124. __WATCHOS_UNAVAILABLE __BRIDGEOS_UNAVAILABLE;
  125. // __OBJC2__
  126. #endif
  127. #endif // __OBJC_EXCEPTION_H_