KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > jdbc > JdbcSQLException


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.jdbc;
6
7 import java.io.PrintStream JavaDoc;
8 import java.io.PrintWriter JavaDoc;
9 import java.sql.SQLException JavaDoc;
10
11 import org.h2.engine.Constants;
12
13 /**
14  * Represents an exception.
15  */

16 public class JdbcSQLException extends SQLException JavaDoc {
17
18     private static final long serialVersionUID = -8200821788226954151L;
19     private Throwable JavaDoc cause;
20     private String JavaDoc originalMessage;
21
22     /**
23      * Creates a SQLException a message, sqlstate and cause.
24      *
25      * @param message the reason
26      * @param state the SQL state
27      * @param cause the exception that was the reason for this exception
28      */

29     public JdbcSQLException(String JavaDoc message, String JavaDoc state, int errorCode, Throwable JavaDoc cause) {
30         super(message + " [" + state + "-" + Constants.BUILD_ID + "]", state, errorCode);
31         this.originalMessage = message;
32         this.cause = cause;
33     }
34
35     /**
36      * INTERNAL
37      */

38     public String JavaDoc getOriginalMessage() {
39         return originalMessage;
40     }
41
42     /**
43      * Prints the stack trace to the standard error stream.
44      */

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

60     public void printStackTrace(PrintWriter JavaDoc s) {
61         if(s!=null) {
62             super.printStackTrace(s);
63             if (cause != null) {
64                 cause.printStackTrace(s);
65             }
66             if(getNextException() != null) {
67                 getNextException().printStackTrace(s);
68             }
69         }
70     }
71
72     /**
73      * Prints the stack trace to the specified print stream.
74      *
75      * @param s the print stream
76      */

77     public void printStackTrace(PrintStream JavaDoc s) {
78         if(s!=null) {
79             super.printStackTrace(s);
80             if (cause != null) {
81                 cause.printStackTrace(s);
82             }
83             if(getNextException() != null) {
84                 getNextException().printStackTrace(s);
85             }
86         }
87     }
88
89     /**
90      * INTERNAL
91      */

92     public Throwable JavaDoc getOriginalCause() {
93         return cause;
94     }
95
96 }
97
Popular Tags