jdk/src/share/classes/java/lang/Throwable.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4666 085aef3c09ff
child 5972 e3f47656e9d9
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
     2
 * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4666
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import  java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The <code>Throwable</code> class is the superclass of all errors and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * exceptions in the Java language. Only objects that are instances of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * class (or one of its subclasses) are thrown by the Java Virtual Machine or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * can be thrown by the Java <code>throw</code> statement. Similarly, only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * this class or one of its subclasses can be the argument type in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>catch</code> clause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
4666
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
    37
 * For the purposes of compile-time checking of exceptions, {@code
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
    38
 * Throwable} and any subclass of {@code Throwable} that is not also a
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
    39
 * subclass of either {@link RuntimeException} or {@link Error} are
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
    40
 * regarded as checked exceptions.
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
    41
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>Instances of two subclasses, {@link java.lang.Error} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * {@link java.lang.Exception}, are conventionally used to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * that exceptional situations have occurred. Typically, these instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * are freshly created in the context of the exceptional situation so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * as to include relevant information (such as stack trace data).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>A throwable contains a snapshot of the execution stack of its thread at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the time it was created. It can also contain a message string that gives
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * more information about the error. Finally, it can contain a <i>cause</i>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * another throwable that caused this throwable to get thrown.  The cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * facility is new in release 1.4.  It is also known as the <i>chained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * exception</i> facility, as the cause can, itself, have a cause, and so on,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * leading to a "chain" of exceptions, each caused by another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>One reason that a throwable may have a cause is that the class that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * throws it is built atop a lower layered abstraction, and an operation on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the upper layer fails due to a failure in the lower layer.  It would be bad
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * design to let the throwable thrown by the lower layer propagate outward, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * it is generally unrelated to the abstraction provided by the upper layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Further, doing so would tie the API of the upper layer to the details of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * its implementation, assuming the lower layer's exception was a checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * exception.  Throwing a "wrapped exception" (i.e., an exception containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * cause) allows the upper layer to communicate the details of the failure to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * its caller without incurring either of these shortcomings.  It preserves
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * the flexibility to change the implementation of the upper layer without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * changing its API (in particular, the set of exceptions thrown by its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * methods).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>A second reason that a throwable may have a cause is that the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * that throws it must conform to a general-purpose interface that does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * permit the method to throw the cause directly.  For example, suppose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * a persistent collection conforms to the {@link java.util.Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Collection} interface, and that its persistence is implemented atop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <tt>java.io</tt>.  Suppose the internals of the <tt>add</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * can throw an {@link java.io.IOException IOException}.  The implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * can communicate the details of the <tt>IOException</tt> to its caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * while conforming to the <tt>Collection</tt> interface by wrapping the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <tt>IOException</tt> in an appropriate unchecked exception.  (The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * specification for the persistent collection should indicate that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * capable of throwing such exceptions.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>A cause can be associated with a throwable in two ways: via a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * constructor that takes the cause as an argument, or via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * {@link #initCause(Throwable)} method.  New throwable classes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * wish to allow causes to be associated with them should provide constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * that take a cause and delegate (perhaps indirectly) to one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <tt>Throwable</tt> constructors that takes a cause.  For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *         lowLevelOp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *     } catch (LowLevelException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *         throw new HighLevelException(le);  // Chaining-aware constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Because the <tt>initCause</tt> method is public, it allows a cause to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * associated with any throwable, even a "legacy throwable" whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * implementation predates the addition of the exception chaining mechanism to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <tt>Throwable</tt>. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *         lowLevelOp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *     } catch (LowLevelException le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *         throw (HighLevelException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                 new HighLevelException().initCause(le);  // Legacy constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <p>Prior to release 1.4, there were many throwables that had their own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * non-standard exception chaining mechanisms (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * {@link ExceptionInInitializerError}, {@link ClassNotFoundException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * {@link java.lang.reflect.UndeclaredThrowableException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * {@link java.lang.reflect.InvocationTargetException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * {@link java.io.WriteAbortedException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * {@link java.security.PrivilegedActionException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * {@link java.awt.print.PrinterIOException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * {@link java.rmi.RemoteException} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * {@link javax.naming.NamingException}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * All of these throwables have been retrofitted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * use the standard exception chaining mechanism, while continuing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * implement their "legacy" chaining mechanisms for compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>Further, as of release 1.4, many general purpose <tt>Throwable</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * classes (for example {@link Exception}, {@link RuntimeException},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * {@link Error}) have been retrofitted with constructors that take
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * a cause.  This was not strictly necessary, due to the existence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <tt>initCause</tt> method, but it is more convenient and expressive to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * delegate to a constructor that takes a cause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <p>By convention, class <code>Throwable</code> and its subclasses have two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * constructors, one that takes no arguments and one that takes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <code>String</code> argument that can be used to produce a detail message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * Further, those subclasses that might likely have a cause associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * them should have two more constructors, one that takes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <code>Throwable</code> (the cause), and one that takes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <code>String</code> (the detail message) and a <code>Throwable</code> (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * cause).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <p>Also introduced in release 1.4 is the {@link #getStackTrace()} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * which allows programmatic access to the stack trace information that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * previously available only in text form, via the various forms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * {@link #printStackTrace()} method.  This information has been added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <i>serialized representation</i> of this class so <tt>getStackTrace</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * and <tt>printStackTrace</tt> will operate properly on a throwable that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * was obtained by deserialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * @author  Josh Bloch (Added exception chaining and programmatic access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *          stack trace in 1.4.)
4666
085aef3c09ff 6915171: Clarify checked/unchecked status of Throwable and its subclasses
darcy
parents: 2947
diff changeset
   150
 * @jls3 11.2 Compile-Time Checking of Exceptions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
public class Throwable implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /** use serialVersionUID from JDK 1.0.2 for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static final long serialVersionUID = -3042686055658047285L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Native code saves some indication of the stack backtrace in this slot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private transient Object backtrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Specific details about the Throwable.  For example, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <tt>FileNotFoundException</tt>, this contains the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * the file that could not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    private String detailMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * The throwable that caused this throwable to get thrown, or null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * throwable was not caused by another throwable, or if the causative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * throwable is unknown.  If this field is equal to this throwable itself,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * it indicates that the cause of this throwable has not yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private Throwable cause = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * The stack trace, as returned by {@link #getStackTrace()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private StackTraceElement[] stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * This field is lazily initialized on first use or serialization and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * nulled out when fillInStackTrace is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Constructs a new throwable with <code>null</code> as its detail message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The cause is not initialized, and may subsequently be initialized by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * call to {@link #initCause}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <p>The {@link #fillInStackTrace()} method is called to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * the stack trace data in the newly created throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public Throwable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Constructs a new throwable with the specified detail message.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * cause is not initialized, and may subsequently be initialized by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * a call to {@link #initCause}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <p>The {@link #fillInStackTrace()} method is called to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the stack trace data in the newly created throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param   message   the detail message. The detail message is saved for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *          later retrieval by the {@link #getMessage()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public Throwable(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        detailMessage = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Constructs a new throwable with the specified detail message and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * cause.  <p>Note that the detail message associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <code>cause</code> is <i>not</i> automatically incorporated in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * this throwable's detail message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <p>The {@link #fillInStackTrace()} method is called to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * the stack trace data in the newly created throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param  message the detail message (which is saved for later retrieval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *         by the {@link #getMessage()} method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param  cause the cause (which is saved for later retrieval by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *         {@link #getCause()} method).  (A <tt>null</tt> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *         permitted, and indicates that the cause is nonexistent or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *         unknown.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public Throwable(String message, Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        detailMessage = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        this.cause = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Constructs a new throwable with the specified cause and a detail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * message of <tt>(cause==null ? null : cause.toString())</tt> (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * typically contains the class and detail message of <tt>cause</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * This constructor is useful for throwables that are little more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * wrappers for other throwables (for example, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * java.security.PrivilegedActionException}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p>The {@link #fillInStackTrace()} method is called to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the stack trace data in the newly created throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param  cause the cause (which is saved for later retrieval by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *         {@link #getCause()} method).  (A <tt>null</tt> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         permitted, and indicates that the cause is nonexistent or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *         unknown.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public Throwable(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        detailMessage = (cause==null ? null : cause.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        this.cause = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Returns the detail message string of this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return  the detail message string of this <tt>Throwable</tt> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *          (which may be <tt>null</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return detailMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Creates a localized description of this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Subclasses may override this method in order to produce a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * locale-specific message.  For subclasses that do not override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * method, the default implementation returns the same result as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <code>getMessage()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @return  The localized description of this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public String getLocalizedMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Returns the cause of this throwable or <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * cause is nonexistent or unknown.  (The cause is the throwable that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * caused this throwable to get thrown.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <p>This implementation returns the cause that was supplied via one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the constructors requiring a <tt>Throwable</tt>, or that was set after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * creation with the {@link #initCause(Throwable)} method.  While it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * typically unnecessary to override this method, a subclass can override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * it to return a cause set by some other means.  This is appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * a "legacy chained throwable" that predates the addition of chained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * exceptions to <tt>Throwable</tt>.  Note that it is <i>not</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * necessary to override any of the <tt>PrintStackTrace</tt> methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * all of which invoke the <tt>getCause</tt> method to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * cause of a throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return  the cause of this throwable or <code>null</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *          cause is nonexistent or unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public Throwable getCause() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return (cause==this ? null : cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Initializes the <i>cause</i> of this throwable to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * (The cause is the throwable that caused this throwable to get thrown.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <p>This method can be called at most once.  It is generally called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * within the constructor, or immediately after creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * throwable.  If this throwable was created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * with {@link #Throwable(Throwable)} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * {@link #Throwable(String,Throwable)}, this method cannot be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * even once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param  cause the cause (which is saved for later retrieval by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *         {@link #getCause()} method).  (A <tt>null</tt> value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *         permitted, and indicates that the cause is nonexistent or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *         unknown.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return  a reference to this <code>Throwable</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @throws IllegalArgumentException if <code>cause</code> is this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *         throwable.  (A throwable cannot be its own cause.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @throws IllegalStateException if this throwable was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *         created with {@link #Throwable(Throwable)} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *         {@link #Throwable(String,Throwable)}, or this method has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *         been called on this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public synchronized Throwable initCause(Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (this.cause != this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            throw new IllegalStateException("Can't overwrite cause");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (cause == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            throw new IllegalArgumentException("Self-causation not permitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        this.cause = cause;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Returns a short description of this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * The result is the concatenation of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <li> the {@linkplain Class#getName() name} of the class of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <li> ": " (a colon and a space)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <li> the result of invoking this object's {@link #getLocalizedMessage}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *      method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * If <tt>getLocalizedMessage</tt> returns <tt>null</tt>, then just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * the class name is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return a string representation of this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        String s = getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        String message = getLocalizedMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return (message != null) ? (s + ": " + message) : s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Prints this throwable and its backtrace to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * standard error stream. This method prints a stack trace for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <code>Throwable</code> object on the error output stream that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the value of the field <code>System.err</code>. The first line of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * output contains the result of the {@link #toString()} method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * this object.  Remaining lines represent data previously recorded by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * the method {@link #fillInStackTrace()}. The format of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * information depends on the implementation, but the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * example may be regarded as typical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * java.lang.NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *         at MyClass.mash(MyClass.java:9)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *         at MyClass.crunch(MyClass.java:6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *         at MyClass.main(MyClass.java:3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * This example was produced by running the program:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * class MyClass {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *     public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *         crunch(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *     static void crunch(int[] a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *         mash(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *     static void mash(int[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *         System.out.println(b[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * The backtrace for a throwable with an initialized, non-null cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * should generally include the backtrace for the cause.  The format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * of this information depends on the implementation, but the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * example may be regarded as typical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * HighLevelException: MidLevelException: LowLevelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *         at Junk.a(Junk.java:13)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *         at Junk.main(Junk.java:4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Caused by: MidLevelException: LowLevelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *         at Junk.c(Junk.java:23)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *         at Junk.b(Junk.java:17)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *         at Junk.a(Junk.java:11)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *         ... 1 more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Caused by: LowLevelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *         at Junk.e(Junk.java:30)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *         at Junk.d(Junk.java:27)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *         at Junk.c(Junk.java:21)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *         ... 3 more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Note the presence of lines containing the characters <tt>"..."</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * These lines indicate that the remainder of the stack trace for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * exception matches the indicated number of frames from the bottom of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * stack trace of the exception that was caused by this exception (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * "enclosing" exception).  This shorthand can greatly reduce the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * of the output in the common case where a wrapped exception is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * from same method as the "causative exception" is caught.  The above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * example was produced by running the program:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * public class Junk {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *     public static void main(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *             a();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *         } catch(HighLevelException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *             e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *     static void a() throws HighLevelException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *             b();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *         } catch(MidLevelException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *             throw new HighLevelException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *     static void b() throws MidLevelException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *         c();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *     static void c() throws MidLevelException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *             d();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *         } catch(LowLevelException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *             throw new MidLevelException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *     static void d() throws LowLevelException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *        e();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *     static void e() throws LowLevelException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *         throw new LowLevelException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * class HighLevelException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *     HighLevelException(Throwable cause) { super(cause); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * class MidLevelException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *     MidLevelException(Throwable cause)  { super(cause); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * class LowLevelException extends Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public void printStackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        printStackTrace(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Prints this throwable and its backtrace to the specified print stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param s <code>PrintStream</code> to use for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public void printStackTrace(PrintStream s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        synchronized (s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            s.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            StackTraceElement[] trace = getOurStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            for (int i=0; i < trace.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                s.println("\tat " + trace[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Throwable ourCause = getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (ourCause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                ourCause.printStackTraceAsCause(s, trace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Print our stack trace as a cause for the specified stack trace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private void printStackTraceAsCause(PrintStream s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                        StackTraceElement[] causedTrace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        // assert Thread.holdsLock(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        // Compute number of frames in common between this and caused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        StackTraceElement[] trace = getOurStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int m = trace.length-1, n = causedTrace.length-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            m--; n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        int framesInCommon = trace.length - 1 - m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        s.println("Caused by: " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        for (int i=0; i <= m; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            s.println("\tat " + trace[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (framesInCommon != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            s.println("\t... " + framesInCommon + " more");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // Recurse if we have a cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        Throwable ourCause = getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (ourCause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            ourCause.printStackTraceAsCause(s, trace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Prints this throwable and its backtrace to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * print writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @param s <code>PrintWriter</code> to use for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public void printStackTrace(PrintWriter s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        synchronized (s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            s.println(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            StackTraceElement[] trace = getOurStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            for (int i=0; i < trace.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                s.println("\tat " + trace[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            Throwable ourCause = getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if (ourCause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                ourCause.printStackTraceAsCause(s, trace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Print our stack trace as a cause for the specified stack trace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    private void printStackTraceAsCause(PrintWriter s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                        StackTraceElement[] causedTrace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        // assert Thread.holdsLock(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        // Compute number of frames in common between this and caused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        StackTraceElement[] trace = getOurStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        int m = trace.length-1, n = causedTrace.length-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            m--; n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        int framesInCommon = trace.length - 1 - m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        s.println("Caused by: " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        for (int i=0; i <= m; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            s.println("\tat " + trace[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if (framesInCommon != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            s.println("\t... " + framesInCommon + " more");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        // Recurse if we have a cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        Throwable ourCause = getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (ourCause != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            ourCause.printStackTraceAsCause(s, trace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Fills in the execution stack trace. This method records within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <code>Throwable</code> object information about the current state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * the stack frames for the current thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @return  a reference to this <code>Throwable</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see     java.lang.Throwable#printStackTrace()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public synchronized native Throwable fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Provides programmatic access to the stack trace information printed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * {@link #printStackTrace()}.  Returns an array of stack trace elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * each representing one stack frame.  The zeroth element of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * (assuming the array's length is non-zero) represents the top of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * stack, which is the last method invocation in the sequence.  Typically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * this is the point at which this throwable was created and thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * The last element of the array (assuming the array's length is non-zero)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * represents the bottom of the stack, which is the first method invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <p>Some virtual machines may, under some circumstances, omit one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * or more stack frames from the stack trace.  In the extreme case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * a virtual machine that has no stack trace information concerning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * this throwable is permitted to return a zero-length array from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * method.  Generally speaking, the array returned by this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * contain one element for every frame that would be printed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <tt>printStackTrace</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @return an array of stack trace elements representing the stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *         pertaining to this throwable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    public StackTraceElement[] getStackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        return getOurStackTrace().clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    private synchronized StackTraceElement[] getOurStackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        // Initialize stack trace if this is the first call to this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (stackTrace == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            int depth = getStackTraceDepth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            stackTrace = new StackTraceElement[depth];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            for (int i=0; i < depth; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                stackTrace[i] = getStackTraceElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * Sets the stack trace elements that will be returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * and related methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * This method, which is designed for use by RPC frameworks and other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * advanced systems, allows the client to override the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * stack trace that is either generated by {@link #fillInStackTrace()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * when a throwable is constructed or deserialized when a throwable is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * read from a serialization stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @param   stackTrace the stack trace elements to be associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * this <code>Throwable</code>.  The specified array is copied by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * call; changes in the specified array after the method invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * returns will have no affect on this <code>Throwable</code>'s stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * trace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @throws NullPointerException if <code>stackTrace</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *         <code>null</code>, or if any of the elements of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *         <code>stackTrace</code> are <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public void setStackTrace(StackTraceElement[] stackTrace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        StackTraceElement[] defensiveCopy = stackTrace.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        for (int i = 0; i < defensiveCopy.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            if (defensiveCopy[i] == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                throw new NullPointerException("stackTrace[" + i + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        this.stackTrace = defensiveCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * Returns the number of elements in the stack trace (or 0 if the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * trace is unavailable).
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   654
     *
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   655
     * package-protection for use by SharedSecrets.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   657
    native int getStackTraceDepth();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Returns the specified element of the stack trace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   662
     * package-protection for use by SharedSecrets.
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   663
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param index index of the element to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @throws IndexOutOfBoundsException if <tt>index &lt; 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *         index &gt;= getStackTraceDepth() </tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2
diff changeset
   668
    native StackTraceElement getStackTraceElement(int index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        getOurStackTrace();  // Ensure that stackTrace field is initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
}