Throwable.hx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. package java.lang;
  2. /*
  3. * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /**
  27. * The {@code Throwable} class is the superclass of all errors and
  28. * exceptions in the Java language. Only objects that are instances of this
  29. * class (or one of its subclasses) are thrown by the Java Virtual Machine or
  30. * can be thrown by the Java {@code throw} statement. Similarly, only
  31. * this class or one of its subclasses can be the argument type in a
  32. * {@code catch} clause.
  33. *
  34. * For the purposes of compile-time checking of exceptions, {@code
  35. * Throwable} and any subclass of {@code Throwable} that is not also a
  36. * subclass of either {@link RuntimeException} or {@link Error} are
  37. * regarded as checked exceptions.
  38. *
  39. * <p>Instances of two subclasses, {@link java.lang.Error} and
  40. * {@link java.lang.Exception}, are conventionally used to indicate
  41. * that exceptional situations have occurred. Typically, these instances
  42. * are freshly created in the context of the exceptional situation so
  43. * as to include relevant information (such as stack trace data).
  44. *
  45. * <p>A throwable contains a snapshot of the execution stack of its
  46. * thread at the time it was created. It can also contain a message
  47. * string that gives more information about the error. Over time, a
  48. * throwable can {@linkplain Throwable#addSuppressed suppress} other
  49. * throwables from being propagated. Finally, the throwable can also
  50. * contain a <i>cause</i>: another throwable that caused this
  51. * throwable to be constructed. The recording of this causal information
  52. * is referred to as the <i>chained exception</i> facility, as the
  53. * cause can, itself, have a cause, and so on, leading to a "chain" of
  54. * exceptions, each caused by another.
  55. *
  56. * <p>One reason that a throwable may have a cause is that the class that
  57. * throws it is built atop a lower layered abstraction, and an operation on
  58. * the upper layer fails due to a failure in the lower layer. It would be bad
  59. * design to let the throwable thrown by the lower layer propagate outward, as
  60. * it is generally unrelated to the abstraction provided by the upper layer.
  61. * Further, doing so would tie the API of the upper layer to the details of
  62. * its implementation, assuming the lower layer's exception was a checked
  63. * exception. Throwing a "wrapped exception" (i.e., an exception containing a
  64. * cause) allows the upper layer to communicate the details of the failure to
  65. * its caller without incurring either of these shortcomings. It preserves
  66. * the flexibility to change the implementation of the upper layer without
  67. * changing its API (in particular, the set of exceptions thrown by its
  68. * methods).
  69. *
  70. * <p>A second reason that a throwable may have a cause is that the method
  71. * that throws it must conform to a general-purpose interface that does not
  72. * permit the method to throw the cause directly. For example, suppose
  73. * a persistent collection conforms to the {@link java.util.Collection
  74. * Collection} interface, and that its persistence is implemented atop
  75. * {@code java.io}. Suppose the internals of the {@code add} method
  76. * can throw an {@link java.io.IOException IOException}. The implementation
  77. * can communicate the details of the {@code IOException} to its caller
  78. * while conforming to the {@code Collection} interface by wrapping the
  79. * {@code IOException} in an appropriate unchecked exception. (The
  80. * specification for the persistent collection should indicate that it is
  81. * capable of throwing such exceptions.)
  82. *
  83. * <p>A cause can be associated with a throwable in two ways: via a
  84. * constructor that takes the cause as an argument, or via the
  85. * {@link #initCause(Throwable)} method. New throwable classes that
  86. * wish to allow causes to be associated with them should provide constructors
  87. * that take a cause and delegate (perhaps indirectly) to one of the
  88. * {@code Throwable} constructors that takes a cause.
  89. *
  90. * Because the {@code initCause} method is public, it allows a cause to be
  91. * associated with any throwable, even a "legacy throwable" whose
  92. * implementation predates the addition of the exception chaining mechanism to
  93. * {@code Throwable}.
  94. *
  95. * <p>By convention, class {@code Throwable} and its subclasses have two
  96. * constructors, one that takes no arguments and one that takes a
  97. * {@code String} argument that can be used to produce a detail message.
  98. * Further, those subclasses that might likely have a cause associated with
  99. * them should have two more constructors, one that takes a
  100. * {@code Throwable} (the cause), and one that takes a
  101. * {@code String} (the detail message) and a {@code Throwable} (the
  102. * cause).
  103. *
  104. * @author unascribed
  105. * @author Josh Bloch (Added exception chaining and programmatic access to
  106. * stack trace in 1.4.)
  107. * @jls 11.2 Compile-Time Checking of Exceptions
  108. * @since JDK1.0
  109. */
  110. @:require(java0) extern class Throwable implements java.io.Serializable
  111. {
  112. /**
  113. * Constructs a new throwable with {@code null} as its detail message.
  114. * The cause is not initialized, and may subsequently be initialized by a
  115. * call to {@link #initCause}.
  116. *
  117. * <p>The {@link #fillInStackTrace()} method is called to initialize
  118. * the stack trace data in the newly created throwable.
  119. */
  120. @:overload public function new() : Void;
  121. /**
  122. * Constructs a new throwable with the specified detail message. The
  123. * cause is not initialized, and may subsequently be initialized by
  124. * a call to {@link #initCause}.
  125. *
  126. * <p>The {@link #fillInStackTrace()} method is called to initialize
  127. * the stack trace data in the newly created throwable.
  128. *
  129. * @param message the detail message. The detail message is saved for
  130. * later retrieval by the {@link #getMessage()} method.
  131. */
  132. @:overload public function new(message : String) : Void;
  133. /**
  134. * Constructs a new throwable with the specified detail message and
  135. * cause. <p>Note that the detail message associated with
  136. * {@code cause} is <i>not</i> automatically incorporated in
  137. * this throwable's detail message.
  138. *
  139. * <p>The {@link #fillInStackTrace()} method is called to initialize
  140. * the stack trace data in the newly created throwable.
  141. *
  142. * @param message the detail message (which is saved for later retrieval
  143. * by the {@link #getMessage()} method).
  144. * @param cause the cause (which is saved for later retrieval by the
  145. * {@link #getCause()} method). (A {@code null} value is
  146. * permitted, and indicates that the cause is nonexistent or
  147. * unknown.)
  148. * @since 1.4
  149. */
  150. @:require(java4) @:overload public function new(message : String, cause : Throwable) : Void;
  151. /**
  152. * Constructs a new throwable with the specified cause and a detail
  153. * message of {@code (cause==null ? null : cause.toString())} (which
  154. * typically contains the class and detail message of {@code cause}).
  155. * This constructor is useful for throwables that are little more than
  156. * wrappers for other throwables (for example, {@link
  157. * java.security.PrivilegedActionException}).
  158. *
  159. * <p>The {@link #fillInStackTrace()} method is called to initialize
  160. * the stack trace data in the newly created throwable.
  161. *
  162. * @param cause the cause (which is saved for later retrieval by the
  163. * {@link #getCause()} method). (A {@code null} value is
  164. * permitted, and indicates that the cause is nonexistent or
  165. * unknown.)
  166. * @since 1.4
  167. */
  168. @:require(java4) @:overload public function new(cause : Throwable) : Void;
  169. /**
  170. * Constructs a new throwable with the specified detail message,
  171. * cause, {@linkplain #addSuppressed suppression} enabled or
  172. * disabled, and writable stack trace enabled or disabled. If
  173. * suppression is disabled, {@link #getSuppressed} for this object
  174. * will return a zero-length array and calls to {@link
  175. * #addSuppressed} that would otherwise append an exception to the
  176. * suppressed list will have no effect. If the writable stack
  177. * trace is false, this constructor will not call {@link
  178. * #fillInStackTrace()}, a {@code null} will be written to the
  179. * {@code stackTrace} field, and subsequent calls to {@code
  180. * fillInStackTrace} and {@link
  181. * #setStackTrace(StackTraceElement[])} will not set the stack
  182. * trace. If the writable stack trace is false, {@link
  183. * #getStackTrace} will return a zero length array.
  184. *
  185. * <p>Note that the other constructors of {@code Throwable} treat
  186. * suppression as being enabled and the stack trace as being
  187. * writable. Subclasses of {@code Throwable} should document any
  188. * conditions under which suppression is disabled and document
  189. * conditions under which the stack trace is not writable.
  190. * Disabling of suppression should only occur in exceptional
  191. * circumstances where special requirements exist, such as a
  192. * virtual machine reusing exception objects under low-memory
  193. * situations. Circumstances where a given exception object is
  194. * repeatedly caught and rethrown, such as to implement control
  195. * flow between two sub-systems, is another situation where
  196. * immutable throwable objects would be appropriate.
  197. *
  198. * @param message the detail message.
  199. * @param cause the cause. (A {@code null} value is permitted,
  200. * and indicates that the cause is nonexistent or unknown.)
  201. * @param enableSuppression whether or not suppression is enabled or disabled
  202. * @param writableStackTrace whether or not the stack trace should be
  203. * writable
  204. *
  205. * @see OutOfMemoryError
  206. * @see NullPointerException
  207. * @see ArithmeticException
  208. * @since 1.7
  209. */
  210. @:require(java7) @:overload private function new(message : String, cause : Throwable, enableSuppression : Bool, writableStackTrace : Bool) : Void;
  211. /**
  212. * Returns the detail message string of this throwable.
  213. *
  214. * @return the detail message string of this {@code Throwable} instance
  215. * (which may be {@code null}).
  216. */
  217. @:overload public function getMessage() : String;
  218. /**
  219. * Creates a localized description of this throwable.
  220. * Subclasses may override this method in order to produce a
  221. * locale-specific message. For subclasses that do not override this
  222. * method, the default implementation returns the same result as
  223. * {@code getMessage()}.
  224. *
  225. * @return The localized description of this throwable.
  226. * @since JDK1.1
  227. */
  228. @:require(java1) @:overload public function getLocalizedMessage() : String;
  229. /**
  230. * Returns the cause of this throwable or {@code null} if the
  231. * cause is nonexistent or unknown. (The cause is the throwable that
  232. * caused this throwable to get thrown.)
  233. *
  234. * <p>This implementation returns the cause that was supplied via one of
  235. * the constructors requiring a {@code Throwable}, or that was set after
  236. * creation with the {@link #initCause(Throwable)} method. While it is
  237. * typically unnecessary to override this method, a subclass can override
  238. * it to return a cause set by some other means. This is appropriate for
  239. * a "legacy chained throwable" that predates the addition of chained
  240. * exceptions to {@code Throwable}. Note that it is <i>not</i>
  241. * necessary to override any of the {@code PrintStackTrace} methods,
  242. * all of which invoke the {@code getCause} method to determine the
  243. * cause of a throwable.
  244. *
  245. * @return the cause of this throwable or {@code null} if the
  246. * cause is nonexistent or unknown.
  247. * @since 1.4
  248. */
  249. @:require(java4) @:overload @:synchronized public function getCause() : Throwable;
  250. /**
  251. * Initializes the <i>cause</i> of this throwable to the specified value.
  252. * (The cause is the throwable that caused this throwable to get thrown.)
  253. *
  254. * <p>This method can be called at most once. It is generally called from
  255. * within the constructor, or immediately after creating the
  256. * throwable. If this throwable was created
  257. * with {@link #Throwable(Throwable)} or
  258. * {@link #Throwable(String,Throwable)}, this method cannot be called
  259. * even once.
  260. *
  261. * <p>An example of using this method on a legacy throwable type
  262. * without other support for setting the cause is:
  263. *
  264. * <pre>
  265. * try {
  266. * lowLevelOp();
  267. * } catch (LowLevelException le) {
  268. * throw (HighLevelException)
  269. * new HighLevelException().initCause(le); // Legacy constructor
  270. * }
  271. * </pre>
  272. *
  273. * @param cause the cause (which is saved for later retrieval by the
  274. * {@link #getCause()} method). (A {@code null} value is
  275. * permitted, and indicates that the cause is nonexistent or
  276. * unknown.)
  277. * @return a reference to this {@code Throwable} instance.
  278. * @throws IllegalArgumentException if {@code cause} is this
  279. * throwable. (A throwable cannot be its own cause.)
  280. * @throws IllegalStateException if this throwable was
  281. * created with {@link #Throwable(Throwable)} or
  282. * {@link #Throwable(String,Throwable)}, or this method has already
  283. * been called on this throwable.
  284. * @since 1.4
  285. */
  286. @:require(java4) @:overload @:synchronized public function initCause(cause : Throwable) : Throwable;
  287. /**
  288. * Returns a short description of this throwable.
  289. * The result is the concatenation of:
  290. * <ul>
  291. * <li> the {@linkplain Class#getName() name} of the class of this object
  292. * <li> ": " (a colon and a space)
  293. * <li> the result of invoking this object's {@link #getLocalizedMessage}
  294. * method
  295. * </ul>
  296. * If {@code getLocalizedMessage} returns {@code null}, then just
  297. * the class name is returned.
  298. *
  299. * @return a string representation of this throwable.
  300. */
  301. @:overload public function toString() : String;
  302. /**
  303. * Prints this throwable and its backtrace to the
  304. * standard error stream. This method prints a stack trace for this
  305. * {@code Throwable} object on the error output stream that is
  306. * the value of the field {@code System.err}. The first line of
  307. * output contains the result of the {@link #toString()} method for
  308. * this object. Remaining lines represent data previously recorded by
  309. * the method {@link #fillInStackTrace()}. The format of this
  310. * information depends on the implementation, but the following
  311. * example may be regarded as typical:
  312. * <blockquote><pre>
  313. * java.lang.NullPointerException
  314. * at MyClass.mash(MyClass.java:9)
  315. * at MyClass.crunch(MyClass.java:6)
  316. * at MyClass.main(MyClass.java:3)
  317. * </pre></blockquote>
  318. * This example was produced by running the program:
  319. * <pre>
  320. * class MyClass {
  321. * public static void main(String[] args) {
  322. * crunch(null);
  323. * }
  324. * static void crunch(int[] a) {
  325. * mash(a);
  326. * }
  327. * static void mash(int[] b) {
  328. * System.out.println(b[0]);
  329. * }
  330. * }
  331. * </pre>
  332. * The backtrace for a throwable with an initialized, non-null cause
  333. * should generally include the backtrace for the cause. The format
  334. * of this information depends on the implementation, but the following
  335. * example may be regarded as typical:
  336. * <pre>
  337. * HighLevelException: MidLevelException: LowLevelException
  338. * at Junk.a(Junk.java:13)
  339. * at Junk.main(Junk.java:4)
  340. * Caused by: MidLevelException: LowLevelException
  341. * at Junk.c(Junk.java:23)
  342. * at Junk.b(Junk.java:17)
  343. * at Junk.a(Junk.java:11)
  344. * ... 1 more
  345. * Caused by: LowLevelException
  346. * at Junk.e(Junk.java:30)
  347. * at Junk.d(Junk.java:27)
  348. * at Junk.c(Junk.java:21)
  349. * ... 3 more
  350. * </pre>
  351. * Note the presence of lines containing the characters {@code "..."}.
  352. * These lines indicate that the remainder of the stack trace for this
  353. * exception matches the indicated number of frames from the bottom of the
  354. * stack trace of the exception that was caused by this exception (the
  355. * "enclosing" exception). This shorthand can greatly reduce the length
  356. * of the output in the common case where a wrapped exception is thrown
  357. * from same method as the "causative exception" is caught. The above
  358. * example was produced by running the program:
  359. * <pre>
  360. * public class Junk {
  361. * public static void main(String args[]) {
  362. * try {
  363. * a();
  364. * } catch(HighLevelException e) {
  365. * e.printStackTrace();
  366. * }
  367. * }
  368. * static void a() throws HighLevelException {
  369. * try {
  370. * b();
  371. * } catch(MidLevelException e) {
  372. * throw new HighLevelException(e);
  373. * }
  374. * }
  375. * static void b() throws MidLevelException {
  376. * c();
  377. * }
  378. * static void c() throws MidLevelException {
  379. * try {
  380. * d();
  381. * } catch(LowLevelException e) {
  382. * throw new MidLevelException(e);
  383. * }
  384. * }
  385. * static void d() throws LowLevelException {
  386. * e();
  387. * }
  388. * static void e() throws LowLevelException {
  389. * throw new LowLevelException();
  390. * }
  391. * }
  392. *
  393. * class HighLevelException extends Exception {
  394. * HighLevelException(Throwable cause) { super(cause); }
  395. * }
  396. *
  397. * class MidLevelException extends Exception {
  398. * MidLevelException(Throwable cause) { super(cause); }
  399. * }
  400. *
  401. * class LowLevelException extends Exception {
  402. * }
  403. * </pre>
  404. * As of release 7, the platform supports the notion of
  405. * <i>suppressed exceptions</i> (in conjunction with the {@code
  406. * try}-with-resources statement). Any exceptions that were
  407. * suppressed in order to deliver an exception are printed out
  408. * beneath the stack trace. The format of this information
  409. * depends on the implementation, but the following example may be
  410. * regarded as typical:
  411. *
  412. * <pre>
  413. * Exception in thread "main" java.lang.Exception: Something happened
  414. * at Foo.bar(Foo.java:10)
  415. * at Foo.main(Foo.java:5)
  416. * Suppressed: Resource$CloseFailException: Resource ID = 0
  417. * at Resource.close(Resource.java:26)
  418. * at Foo.bar(Foo.java:9)
  419. * ... 1 more
  420. * </pre>
  421. * Note that the "... n more" notation is used on suppressed exceptions
  422. * just at it is used on causes. Unlike causes, suppressed exceptions are
  423. * indented beyond their "containing exceptions."
  424. *
  425. * <p>An exception can have both a cause and one or more suppressed
  426. * exceptions:
  427. * <pre>
  428. * Exception in thread "main" java.lang.Exception: Main block
  429. * at Foo3.main(Foo3.java:7)
  430. * Suppressed: Resource$CloseFailException: Resource ID = 2
  431. * at Resource.close(Resource.java:26)
  432. * at Foo3.main(Foo3.java:5)
  433. * Suppressed: Resource$CloseFailException: Resource ID = 1
  434. * at Resource.close(Resource.java:26)
  435. * at Foo3.main(Foo3.java:5)
  436. * Caused by: java.lang.Exception: I did it
  437. * at Foo3.main(Foo3.java:8)
  438. * </pre>
  439. * Likewise, a suppressed exception can have a cause:
  440. * <pre>
  441. * Exception in thread "main" java.lang.Exception: Main block
  442. * at Foo4.main(Foo4.java:6)
  443. * Suppressed: Resource2$CloseFailException: Resource ID = 1
  444. * at Resource2.close(Resource2.java:20)
  445. * at Foo4.main(Foo4.java:5)
  446. * Caused by: java.lang.Exception: Rats, you caught me
  447. * at Resource2$CloseFailException.<init>(Resource2.java:45)
  448. * ... 2 more
  449. * </pre>
  450. */
  451. @:overload public function printStackTrace() : Void;
  452. /**
  453. * Prints this throwable and its backtrace to the specified print stream.
  454. *
  455. * @param s {@code PrintStream} to use for output
  456. */
  457. @:overload public function printStackTrace(s : java.io.PrintStream) : Void;
  458. /**
  459. * Prints this throwable and its backtrace to the specified
  460. * print writer.
  461. *
  462. * @param s {@code PrintWriter} to use for output
  463. * @since JDK1.1
  464. */
  465. @:require(java1) @:overload public function printStackTrace(s : java.io.PrintWriter) : Void;
  466. /**
  467. * Fills in the execution stack trace. This method records within this
  468. * {@code Throwable} object information about the current state of
  469. * the stack frames for the current thread.
  470. *
  471. * <p>If the stack trace of this {@code Throwable} {@linkplain
  472. * Throwable#Throwable(String, Throwable, boolean, boolean) is not
  473. * writable}, calling this method has no effect.
  474. *
  475. * @return a reference to this {@code Throwable} instance.
  476. * @see java.lang.Throwable#printStackTrace()
  477. */
  478. @:overload @:synchronized public function fillInStackTrace() : Throwable;
  479. /**
  480. * Provides programmatic access to the stack trace information printed by
  481. * {@link #printStackTrace()}. Returns an array of stack trace elements,
  482. * each representing one stack frame. The zeroth element of the array
  483. * (assuming the array's length is non-zero) represents the top of the
  484. * stack, which is the last method invocation in the sequence. Typically,
  485. * this is the point at which this throwable was created and thrown.
  486. * The last element of the array (assuming the array's length is non-zero)
  487. * represents the bottom of the stack, which is the first method invocation
  488. * in the sequence.
  489. *
  490. * <p>Some virtual machines may, under some circumstances, omit one
  491. * or more stack frames from the stack trace. In the extreme case,
  492. * a virtual machine that has no stack trace information concerning
  493. * this throwable is permitted to return a zero-length array from this
  494. * method. Generally speaking, the array returned by this method will
  495. * contain one element for every frame that would be printed by
  496. * {@code printStackTrace}. Writes to the returned array do not
  497. * affect future calls to this method.
  498. *
  499. * @return an array of stack trace elements representing the stack trace
  500. * pertaining to this throwable.
  501. * @since 1.4
  502. */
  503. @:require(java4) @:overload public function getStackTrace() : java.NativeArray<java.lang.StackTraceElement>;
  504. /**
  505. * Sets the stack trace elements that will be returned by
  506. * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
  507. * and related methods.
  508. *
  509. * This method, which is designed for use by RPC frameworks and other
  510. * advanced systems, allows the client to override the default
  511. * stack trace that is either generated by {@link #fillInStackTrace()}
  512. * when a throwable is constructed or deserialized when a throwable is
  513. * read from a serialization stream.
  514. *
  515. * <p>If the stack trace of this {@code Throwable} {@linkplain
  516. * Throwable#Throwable(String, Throwable, boolean, boolean) is not
  517. * writable}, calling this method has no effect other than
  518. * validating its argument.
  519. *
  520. * @param stackTrace the stack trace elements to be associated with
  521. * this {@code Throwable}. The specified array is copied by this
  522. * call; changes in the specified array after the method invocation
  523. * returns will have no affect on this {@code Throwable}'s stack
  524. * trace.
  525. *
  526. * @throws NullPointerException if {@code stackTrace} is
  527. * {@code null} or if any of the elements of
  528. * {@code stackTrace} are {@code null}
  529. *
  530. * @since 1.4
  531. */
  532. @:require(java4) @:overload public function setStackTrace(stackTrace : java.NativeArray<java.lang.StackTraceElement>) : Void;
  533. /**
  534. * Appends the specified exception to the exceptions that were
  535. * suppressed in order to deliver this exception. This method is
  536. * thread-safe and typically called (automatically and implicitly)
  537. * by the {@code try}-with-resources statement.
  538. *
  539. * <p>The suppression behavior is enabled <em>unless</em> disabled
  540. * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
  541. * a constructor}. When suppression is disabled, this method does
  542. * nothing other than to validate its argument.
  543. *
  544. * <p>Note that when one exception {@linkplain
  545. * #initCause(Throwable) causes} another exception, the first
  546. * exception is usually caught and then the second exception is
  547. * thrown in response. In other words, there is a causal
  548. * connection between the two exceptions.
  549. *
  550. * In contrast, there are situations where two independent
  551. * exceptions can be thrown in sibling code blocks, in particular
  552. * in the {@code try} block of a {@code try}-with-resources
  553. * statement and the compiler-generated {@code finally} block
  554. * which closes the resource.
  555. *
  556. * In these situations, only one of the thrown exceptions can be
  557. * propagated. In the {@code try}-with-resources statement, when
  558. * there are two such exceptions, the exception originating from
  559. * the {@code try} block is propagated and the exception from the
  560. * {@code finally} block is added to the list of exceptions
  561. * suppressed by the exception from the {@code try} block. As an
  562. * exception unwinds the stack, it can accumulate multiple
  563. * suppressed exceptions.
  564. *
  565. * <p>An exception may have suppressed exceptions while also being
  566. * caused by another exception. Whether or not an exception has a
  567. * cause is semantically known at the time of its creation, unlike
  568. * whether or not an exception will suppress other exceptions
  569. * which is typically only determined after an exception is
  570. * thrown.
  571. *
  572. * <p>Note that programmer written code is also able to take
  573. * advantage of calling this method in situations where there are
  574. * multiple sibling exceptions and only one can be propagated.
  575. *
  576. * @param exception the exception to be added to the list of
  577. * suppressed exceptions
  578. * @throws IllegalArgumentException if {@code exception} is this
  579. * throwable; a throwable cannot suppress itself.
  580. * @throws NullPointerException if {@code exception} is {@code null}
  581. * @since 1.7
  582. */
  583. @:require(java7) @:overload @:final @:synchronized public function addSuppressed(exception : Throwable) : Void;
  584. /**
  585. * Returns an array containing all of the exceptions that were
  586. * suppressed, typically by the {@code try}-with-resources
  587. * statement, in order to deliver this exception.
  588. *
  589. * If no exceptions were suppressed or {@linkplain
  590. * #Throwable(String, Throwable, boolean, boolean) suppression is
  591. * disabled}, an empty array is returned. This method is
  592. * thread-safe. Writes to the returned array do not affect future
  593. * calls to this method.
  594. *
  595. * @return an array containing all of the exceptions that were
  596. * suppressed to deliver this exception.
  597. * @since 1.7
  598. */
  599. @:require(java7) @:overload @:final @:synchronized public function getSuppressed() : java.NativeArray<Throwable>;
  600. }