/
FBXAException.java
155 lines (133 loc) · 4.21 KB
/
FBXAException.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.jaybird.xca;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.transaction.xa.XAException;
/**
* Convenience exception that adds constructor taking message and error code
* together.
*
* @author <a href="mailto:rrokytskyy@users.sourceforge.net">Roman Rokytskyy</a>
*/
public class FBXAException extends XAException {
public FBXAException() {
super();
}
/**
* Create a new instance of <code>FBXAException</code> with a given
* message.
*
* @param msg The string message for this exception
*/
public FBXAException(String msg) {
super(msg);
}
/**
* Create a new instance of <code>FBXAException</code> based around
* a specific error code.
*
* @param errorCode The error code for this exception
*/
public FBXAException(int errorCode) {
super(errorCode);
}
/**
* Create a new instance of <code>FBXAException</code> based around
* a message and specific error code.
*
* @param msg The string message for this exception
* @param errorCode The error code for this exception
*/
public FBXAException(String msg, int errorCode) {
this(msg);
this.errorCode = errorCode;
}
private Exception reason;
/**
* Create a new instance of <code>FBXAException</code> wrapped around
* an underlying exception.
*
* @param errorCode The error code for this exception
* @param reason The underlying exception
*/
public FBXAException(int errorCode, Exception reason) {
this(errorCode);
this.reason = reason;
initCause(reason);
}
/**
* Create a new instance of <code>FBXAException</code> based around
* a message and with an underlying exception.
*
* @param msg The string message for this exception
* @param errorCode The error code for this exception
* @param reason The underlying exception
*/
public FBXAException(String msg, int errorCode, Exception reason) {
this(msg, errorCode);
this.reason = reason;
initCause(reason);
}
/**
* Get message of this exception.
*
* @return combined message of this exception and original exception.
*/
public String getMessage() {
String s = super.getMessage();
if (reason == null)
return s;
if (s == null)
return reason.getMessage();
return s + "\nReason: " + reason.getMessage();
}
/** Print a stack trace for this exception to <code>STDERR</code>. */
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* Print a stack trace for this exception with a
* given <code>PrintStream</code>.
*
* @param s The <code>PrintStream</code> to which the stack trace will
* be written
*/
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
if (reason != null) {
s.print("at ");
reason.printStackTrace(s);
}
}
/**
* Print a stack trace for this exception with a
* given <code>PrintWriter</code>.
*
* @param s The <code>PrintWriter</code> to which the stack trace will
* be written
*/
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
if (reason != null) {
s.print("at ");
reason.printStackTrace(s);
}
}
}