View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose;
17  
18  import java.io.OutputStreamWriter;
19  import java.io.PrintStream;
20  import java.io.PrintWriter;
21  
22  
23  /***
24   * Useful for creating exceptions out of DiagnosticMessages
25   * 
26   * @author jmccrindle
27   */
28  public class StoredException extends DiagnosticException {
29  
30  	private final String message;
31  	private final String body;
32  
33  	/***
34  	 * @param message the exceptions message
35  	 * @param body the stacktrace
36  	 */
37  	public StoredException(String message, String body) {
38  		this.message = message;
39  		this.body = body;
40  	}
41  	
42  	/***
43  	 * @see java.lang.Throwable#getMessage()
44  	 */
45  	public String getMessage() {
46  		return message;
47  	}
48  
49  	/***
50  	 * @see java.lang.Throwable#getLocalizedMessage()
51  	 */
52  	public String getLocalizedMessage() {
53  		return message;
54  	}
55  	
56  	/***
57  	 * @see java.lang.Throwable#printStackTrace()
58  	 */
59  	public void printStackTrace() {
60  		printStackTrace(System.out);
61  	}
62  	
63  	/***
64  	 * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
65  	 */
66  	public void printStackTrace(PrintStream out) {
67  		printStackTrace(new PrintWriter(new OutputStreamWriter(out)));
68  	}
69  	
70  	/***
71  	 * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
72  	 */
73  	public void printStackTrace(PrintWriter out) {
74  		out.println(message);
75  		out.println(body);
76  	}
77  }