objc-exception.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  32. OBJC_EXPORT void
  33. objc_exception_try_enter(void * _Nonnull localExceptionData)
  34. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  35. OBJC_EXPORT void
  36. objc_exception_try_exit(void * _Nonnull localExceptionData)
  37. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  38. OBJC_EXPORT id _Nonnull
  39. objc_exception_extract(void * _Nonnull localExceptionData)
  40. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  41. OBJC_EXPORT int objc_exception_match(Class _Nonnull exceptionClass,
  42. id _Nonnull exception)
  43. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  44. typedef struct {
  45. int version;
  46. void (* _Nonnull throw_exc)(id _Nonnull); // version 0
  47. void (* _Nonnull try_enter)(void * _Nonnull); // version 0
  48. void (* _Nonnull try_exit)(void * _Nonnull); // version 0
  49. id _Nonnull (* _Nonnull extract)(void * _Nonnull); // version 0
  50. int (* _Nonnull match)(Class _Nonnull, id _Nonnull); // version 0
  51. } objc_exception_functions_t;
  52. // get table; version tells how many
  53. OBJC_EXPORT void
  54. objc_exception_get_functions(objc_exception_functions_t * _Nullable table)
  55. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  56. // set table
  57. OBJC_EXPORT void
  58. objc_exception_set_functions(objc_exception_functions_t * _Nullable table)
  59. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.3);
  60. // !__OBJC2__
  61. #else
  62. // __OBJC2__
  63. typedef id _Nonnull (*objc_exception_preprocessor)(id _Nonnull exception);
  64. typedef int (*objc_exception_matcher)(Class _Nonnull catch_type,
  65. id _Nonnull exception);
  66. typedef void (*objc_uncaught_exception_handler)(id _Null_unspecified /* _Nonnull */ exception);
  67. typedef void (*objc_exception_handler)(id _Nullable unused,
  68. void * _Nullable context);
  69. /**
  70. * Throw a runtime exception. This function is inserted by the compiler
  71. * where \c @throw would otherwise be.
  72. *
  73. * @param exception The exception to be thrown.
  74. */
  75. OBJC_EXPORT void
  76. objc_exception_throw(id _Nonnull exception)
  77. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  78. OBJC_EXPORT void
  79. objc_exception_rethrow(void)
  80. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  81. OBJC_EXPORT id _Nonnull
  82. objc_begin_catch(void * _Nonnull exc_buf)
  83. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  84. OBJC_EXPORT void
  85. objc_end_catch(void)
  86. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  87. OBJC_EXPORT void
  88. objc_terminate(void)
  89. OBJC_AVAILABLE(10.8, 6.0, 9.0, 1.0, 2.0);
  90. OBJC_EXPORT objc_exception_preprocessor _Nonnull
  91. objc_setExceptionPreprocessor(objc_exception_preprocessor _Nonnull fn)
  92. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  93. OBJC_EXPORT objc_exception_matcher _Nonnull
  94. objc_setExceptionMatcher(objc_exception_matcher _Nonnull fn)
  95. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  96. OBJC_EXPORT objc_uncaught_exception_handler _Nonnull
  97. objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler _Nonnull fn)
  98. OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0);
  99. // Not for iOS.
  100. OBJC_EXPORT uintptr_t
  101. objc_addExceptionHandler(objc_exception_handler _Nonnull fn,
  102. void * _Nullable context)
  103. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.5);
  104. OBJC_EXPORT void
  105. objc_removeExceptionHandler(uintptr_t token)
  106. OBJC_OSX_AVAILABLE_OTHERS_UNAVAILABLE(10.5);
  107. // __OBJC2__
  108. #endif
  109. #endif // __OBJC_EXCEPTION_H_