Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

161 lines
6.8KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Exceptions (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Exceptions (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Exceptions (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Objective_002dC.html#Objective_002dC" rel="up" title="Objective-C">
  30. <link href="Synchronization.html#Synchronization" rel="next" title="Synchronization">
  31. <link href="compatibility_005falias.html#compatibility_005falias" rel="prev" title="compatibility_alias">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Exceptions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Synchronization.html#Synchronization" accesskey="n" rel="next">Synchronization</a>, Previous: <a href="compatibility_005falias.html#compatibility_005falias" accesskey="p" rel="prev">compatibility_alias</a>, Up: <a href="Objective_002dC.html#Objective_002dC" accesskey="u" rel="up">Objective-C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Exceptions-1"></a>
  68. <h3 class="section">8.7 Exceptions</h3>
  69. <p>GNU Objective-C provides exception support built into the language, as
  70. in the following example:
  71. </p>
  72. <div class="smallexample">
  73. <pre class="smallexample"> @try {
  74. &hellip;
  75. @throw expr;
  76. &hellip;
  77. }
  78. @catch (AnObjCClass *exc) {
  79. &hellip;
  80. @throw expr;
  81. &hellip;
  82. @throw;
  83. &hellip;
  84. }
  85. @catch (AnotherClass *exc) {
  86. &hellip;
  87. }
  88. @catch (id allOthers) {
  89. &hellip;
  90. }
  91. @finally {
  92. &hellip;
  93. @throw expr;
  94. &hellip;
  95. }
  96. </pre></div>
  97. <p>The <code>@throw</code> statement may appear anywhere in an Objective-C or
  98. Objective-C++ program; when used inside of a <code>@catch</code> block, the
  99. <code>@throw</code> may appear without an argument (as shown above), in
  100. which case the object caught by the <code>@catch</code> will be rethrown.
  101. </p>
  102. <p>Note that only (pointers to) Objective-C objects may be thrown and
  103. caught using this scheme. When an object is thrown, it will be caught
  104. by the nearest <code>@catch</code> clause capable of handling objects of
  105. that type, analogously to how <code>catch</code> blocks work in C++ and
  106. Java. A <code>@catch(id &hellip;)</code> clause (as shown above) may also
  107. be provided to catch any and all Objective-C exceptions not caught by
  108. previous <code>@catch</code> clauses (if any).
  109. </p>
  110. <p>The <code>@finally</code> clause, if present, will be executed upon exit
  111. from the immediately preceding <code>@try &hellip; @catch</code> section.
  112. This will happen regardless of whether any exceptions are thrown,
  113. caught or rethrown inside the <code>@try &hellip; @catch</code> section,
  114. analogously to the behavior of the <code>finally</code> clause in Java.
  115. </p>
  116. <p>There are several caveats to using the new exception mechanism:
  117. </p>
  118. <ul>
  119. <li> The <samp>-fobjc-exceptions</samp> command line option must be used when
  120. compiling Objective-C files that use exceptions.
  121. </li><li> With the GNU runtime, exceptions are always implemented as &ldquo;native&rdquo;
  122. exceptions and it is recommended that the <samp>-fexceptions</samp> and
  123. <samp>-shared-libgcc</samp> options are used when linking.
  124. </li><li> With the NeXT runtime, although currently designed to be binary
  125. compatible with <code>NS_HANDLER</code>-style idioms provided by the
  126. <code>NSException</code> class, the new exceptions can only be used on Mac
  127. OS X 10.3 (Panther) and later systems, due to additional functionality
  128. needed in the NeXT Objective-C runtime.
  129. </li><li> As mentioned above, the new exceptions do not support handling
  130. types other than Objective-C objects. Furthermore, when used from
  131. Objective-C++, the Objective-C exception model does not interoperate with C++
  132. exceptions at this time. This means you cannot <code>@throw</code> an exception
  133. from Objective-C and <code>catch</code> it in C++, or vice versa
  134. (i.e., <code>throw &hellip; @catch</code>).
  135. </li></ul>
  136. <hr>
  137. <div class="header">
  138. <p>
  139. Next: <a href="Synchronization.html#Synchronization" accesskey="n" rel="next">Synchronization</a>, Previous: <a href="compatibility_005falias.html#compatibility_005falias" accesskey="p" rel="prev">compatibility_alias</a>, Up: <a href="Objective_002dC.html#Objective_002dC" accesskey="u" rel="up">Objective-C</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  140. </div>
  141. </body>
  142. </html>