src/share/classes/java/lang/Throwable.java

Print this page




 941             // older JDK releases; treat such exceptions as having
 942             // empty stack traces.
 943             stackTrace = UNASSIGNED_STACK.clone();
 944         }
 945     }
 946 
 947     /**
 948      * Write a {@code Throwable} object to a stream.
 949      *
 950      * A {@code null} stack trace field is represented in the serial
 951      * form as a one-element array whose element is equal to {@code
 952      * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 953      */
 954     private synchronized void writeObject(ObjectOutputStream s)
 955         throws IOException {
 956         // Ensure that the stackTrace field is initialized to a
 957         // non-null value, if appropriate.  As of JDK 7, a null stack
 958         // trace field is a valid value indicating the stack trace
 959         // should not be set.
 960         getOurStackTrace();
 961         ObjectOutputStream.PutField fields = s.putFields();
 962 
 963         fields.put("detailMessage", detailMessage);
 964         fields.put("cause", cause);
 965         // Serialize a null stacktrace using the stack trace sentinel.
 966         if (stackTrace == null)
 967             fields.put("stackTrace", SentinelHolder.STACK_TRACE_SENTINEL);
 968         else
 969             fields.put("stackTrace", stackTrace);
 970         fields.put("suppressedExceptions", suppressedExceptions);
 971 
 972         s.writeFields();
 973     }
 974 
 975     /**
 976      * Appends the specified exception to the exceptions that were
 977      * suppressed in order to deliver this exception. This method is
 978      * typically called (automatically and implicitly) by the {@code
 979      * try}-with-resources statement.
 980      *
 981      * <p>The suppression behavior is enabled <em>unless</em> disabled
 982      * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
 983      * a constructor}.  When suppression is disabled, this method does
 984      * nothing other than to validate its argument.
 985      *
 986      * <p>Note that when one exception {@linkplain
 987      * #initCause(Throwable) causes} another exception, the first
 988      * exception is usually caught and then the second exception is
 989      * thrown in response.  In other words, there is a causal
 990      * connection between the two exceptions.
 991      *
 992      * In contrast, there are situations where two independent




 941             // older JDK releases; treat such exceptions as having
 942             // empty stack traces.
 943             stackTrace = UNASSIGNED_STACK.clone();
 944         }
 945     }
 946 
 947     /**
 948      * Write a {@code Throwable} object to a stream.
 949      *
 950      * A {@code null} stack trace field is represented in the serial
 951      * form as a one-element array whose element is equal to {@code
 952      * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
 953      */
 954     private synchronized void writeObject(ObjectOutputStream s)
 955         throws IOException {
 956         // Ensure that the stackTrace field is initialized to a
 957         // non-null value, if appropriate.  As of JDK 7, a null stack
 958         // trace field is a valid value indicating the stack trace
 959         // should not be set.
 960         getOurStackTrace();

 961 
 962         StackTraceElement[] oldStackTrace = stackTrace;
 963         try {

 964             if (stackTrace == null)
 965                 stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
 966             s.defaultWriteObject();
 967         } finally {
 968             stackTrace = oldStackTrace;
 969         }

 970     }
 971 
 972     /**
 973      * Appends the specified exception to the exceptions that were
 974      * suppressed in order to deliver this exception. This method is
 975      * typically called (automatically and implicitly) by the {@code
 976      * try}-with-resources statement.
 977      *
 978      * <p>The suppression behavior is enabled <em>unless</em> disabled
 979      * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
 980      * a constructor}.  When suppression is disabled, this method does
 981      * nothing other than to validate its argument.
 982      *
 983      * <p>Note that when one exception {@linkplain
 984      * #initCause(Throwable) causes} another exception, the first
 985      * exception is usually caught and then the second exception is
 986      * thrown in response.  In other words, there is a causal
 987      * connection between the two exceptions.
 988      *
 989      * In contrast, there are situations where two independent