1 /**
2  * The utillib library.
3  * More information is available at http://www.jinchess.com/.
4  * Copyright (C) 2002 Alexander Maryanovsky.
5  * All rights reserved.
6  *
7  * The utillib library is free software; you can redistribute
8  * it and/or modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * The utillib library is distributed in the hope that it will
13  * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with utillib library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 
22 package free.util;
23 
24 
25 /**
26  * Thrown when the format of something is wrong.
27  */
28 
29 public class FormatException extends RuntimeException{
30 
31 
32 
33   /**
34    * The "reason" exception that caused this exception to be thrown.
35    */
36 
37   private final Throwable realException;
38 
39 
40 
41   /**
42    * Creates a new <code>FormatException</code> with the specified "reason"
43    * <code>Throwable</code> and message.
44    */
45 
FormatException(Throwable realException, String message)46   public FormatException(Throwable realException, String message){
47     super(message);
48 
49     this.realException = realException;
50   }
51 
52 
53 
54   /**
55    * Creates a new <code>FormatException</code> with the specified "reason"
56    * <code>Throwable</code>.
57    */
58 
FormatException(Throwable realException)59   public FormatException(Throwable realException){
60     this(realException, null);
61   }
62 
63 
64 
65   /**
66    * Creates a new <code>FormatException</code> with the specified message.
67    */
68 
FormatException(String message)69   public FormatException(String message){
70     this(null, message);
71   }
72 
73 
74 
75   /**
76    * Creates a new <code>FormatException</code>.
77    */
78 
FormatException()79   public FormatException(){
80     this(null, null);
81   }
82 
83 
84 
85   /**
86    * Returns the actual throwable that resulted in this exception. For example,
87    * if an attempt to parse a string as an integer occurred, this should be
88    * the NumberFormatException that was thrown by <code>Integer.parseInt</code>.
89    */
90 
getReason()91   public Throwable getReason(){
92     return realException;
93   }
94 
95 
96 
97   /**
98    * Prints the stack trace of this FormatException to the standard error stream.
99    */
100 
printStackTrace()101   public void printStackTrace(){
102     printStackTrace(System.err);
103   }
104 
105 
106 
107   /**
108    * Prints the stack trace of this FormatException to the specified PrintStream.
109    *
110    * @param s <code>PrintStream</code> to use for output
111    */
112 
printStackTrace(java.io.PrintStream s)113   public void printStackTrace(java.io.PrintStream s) {
114     synchronized(s){
115       if (realException != null){
116         s.println("++++");
117         super.printStackTrace(s);
118         realException.printStackTrace(s);
119         s.println("----");
120       }
121       else
122         super.printStackTrace(s);
123     }
124   }
125 
126 
127 
128   /**
129    * Prints the stack trace of this FormatException to the specified PrintWriter.
130    *
131    * @param s <code>PrintWriter</code> to use for output
132    */
133 
printStackTrace(java.io.PrintWriter s)134   public void printStackTrace(java.io.PrintWriter s) {
135     synchronized(s){
136       if (realException != null){
137         s.println("++++");
138         super.printStackTrace(s);
139         realException.printStackTrace(s);
140         s.println("----");
141       }
142       else
143         super.printStackTrace(s);
144     }
145   }
146 
147 
148 
149 }
150