jdk/src/share/classes/java/lang/Throwable.java
changeset 17176 d7ee1e315fe7
parent 14342 8435a30053c1
child 22581 e868cde95050
equal deleted inserted replaced
17175:d9614db37fd2 17176:d7ee1e315fe7
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   451      *         been called on this throwable.
   451      *         been called on this throwable.
   452      * @since  1.4
   452      * @since  1.4
   453      */
   453      */
   454     public synchronized Throwable initCause(Throwable cause) {
   454     public synchronized Throwable initCause(Throwable cause) {
   455         if (this.cause != this)
   455         if (this.cause != this)
   456             throw new IllegalStateException("Can't overwrite cause");
   456             throw new IllegalStateException("Can't overwrite cause with " +
       
   457                                             Objects.toString(cause, "a null"), this);
   457         if (cause == this)
   458         if (cause == this)
   458             throw new IllegalArgumentException("Self-causation not permitted");
   459             throw new IllegalArgumentException("Self-causation not permitted", this);
   459         this.cause = cause;
   460         this.cause = cause;
   460         return this;
   461         return this;
   461     }
   462     }
   462 
   463 
   463     /**
   464     /**
  1037      * @throws NullPointerException if {@code exception} is {@code null}
  1038      * @throws NullPointerException if {@code exception} is {@code null}
  1038      * @since 1.7
  1039      * @since 1.7
  1039      */
  1040      */
  1040     public final synchronized void addSuppressed(Throwable exception) {
  1041     public final synchronized void addSuppressed(Throwable exception) {
  1041         if (exception == this)
  1042         if (exception == this)
  1042             throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
  1043             throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE, exception);
  1043 
  1044 
  1044         if (exception == null)
  1045         if (exception == null)
  1045             throw new NullPointerException(NULL_CAUSE_MESSAGE);
  1046             throw new NullPointerException(NULL_CAUSE_MESSAGE);
  1046 
  1047 
  1047         if (suppressedExceptions == null) // Suppressed exceptions not recorded
  1048         if (suppressedExceptions == null) // Suppressed exceptions not recorded