KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > ast > DetailedSemanticException


1 // $Id: DetailedSemanticException.java,v 1.5 2005/02/12 20:27:50 pgmjsd Exp $
2
package org.hibernate.hql.ast;
3
4 import antlr.SemanticException;
5
6 import java.io.PrintStream JavaDoc;
7 import java.io.PrintWriter JavaDoc;
8
9 /**
10  * Thrown when a call to the underlying Hibernate engine fails, indicating
11  * some form of semantic exception (e.g. a class name was not found in the
12  * current mappings, etc.).
13  */

14 public class DetailedSemanticException extends SemanticException {
15     private Throwable JavaDoc cause;
16     private boolean showCauseMessage = true;
17
18     public DetailedSemanticException(String JavaDoc message) {
19         super( message );
20     }
21
22     public DetailedSemanticException(String JavaDoc s, Throwable JavaDoc e) {
23         super( s );
24         cause = e;
25     }
26
27     /**
28      * Converts everything to a string.
29      *
30      * @return a string.
31      */

32     public String JavaDoc toString() {
33         if ( cause == null || ( !showCauseMessage ) ) {
34             return super.toString();
35         }
36         else {
37             return super.toString() + "\n[cause=" + cause.toString() + "]";
38         }
39     }
40
41     /**
42      * Prints a stack trace.
43      */

44     public void printStackTrace() {
45         super.printStackTrace();
46         if ( cause != null ) {
47             cause.printStackTrace();
48         }
49     }
50
51     /**
52      * Prints a stack trace to the specified print stream.
53      *
54      * @param s the print stream.
55      */

56     public void printStackTrace(PrintStream JavaDoc s) {
57         super.printStackTrace( s );
58         if ( cause != null ) {
59             s.println( "Cause:" );
60             cause.printStackTrace( s );
61         }
62     }
63
64     /**
65      * Prints this throwable and its backtrace to the specified print writer.
66      *
67      * @param w the print writer.s
68      */

69     public void printStackTrace(PrintWriter JavaDoc w) {
70         super.printStackTrace( w );
71         if ( cause != null ) {
72             w.println( "Cause:" );
73             cause.printStackTrace( w );
74         }
75     }
76
77 }
78
Popular Tags