1 22 23 24 package com.mchange.lang; 25 26 import java.io.*; 27 import com.mchange.v2.lang.VersionUtils; 28 29 33 public class PotentiallySecondaryException extends Exception implements PotentiallySecondary 34 { 35 final static String NESTED_MSG = ">>>>>>>>>> NESTED EXCEPTION >>>>>>>>"; 36 37 Throwable nested; 38 39 public PotentiallySecondaryException(String msg, Throwable t) 40 { 41 super(msg); 42 this.nested = t; 43 } 44 45 public PotentiallySecondaryException(Throwable t) 46 {this("", t);} 47 48 public PotentiallySecondaryException(String msg) 49 {this(msg, null);} 50 51 public PotentiallySecondaryException() 52 {this("", null);} 53 54 public Throwable getNestedThrowable() 55 {return nested;} 56 57 private void setNested(Throwable t) 58 { 59 this.nested = t; 60 if ( VersionUtils.isAtLeastJavaVersion14() ) 61 this.initCause( t ); 62 } 63 64 public void printStackTrace(PrintWriter pw) 65 { 66 super.printStackTrace(pw); 67 if ( !VersionUtils.isAtLeastJavaVersion14() && nested != null) 68 { 69 pw.println(NESTED_MSG); 70 nested.printStackTrace(pw); 71 } 72 } 73 74 public void printStackTrace(PrintStream ps) 75 { 76 super.printStackTrace(ps); 77 if ( !VersionUtils.isAtLeastJavaVersion14() && nested != null) 78 { 79 ps.println("NESTED_MSG"); 80 nested.printStackTrace(ps); 81 } 82 } 83 84 public void printStackTrace() 85 { 86 if ( VersionUtils.isAtLeastJavaVersion14() ) 87 super.printStackTrace(); 88 else 89 this.printStackTrace(System.err); 90 } 91 } 92 | Popular Tags |