org.firebirdsql.jca.FBResourceException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaybird Show documentation
Show all versions of jaybird Show documentation
JDBC Driver for the Firebird RDBMS
/*
* Firebird Open Source J2ee 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 CVS history command.
*
* All rights reserved.
*/
package org.firebirdsql.jca;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.resource.ResourceException;
/**
* FBResourceException
should be used in places where
* {@link ResourceException} should be thrown according to the interface
* specification, but we do not want to loose exception that we caught.
*
* Example:
*
* try {
* // execute some code here
* ...
* } catch(GDSException gdsex) {
* throw new FBResourceException(gdsex);
* }
*
*
* @author Roman Rokytskyy
*/
public class FBResourceException extends ResourceException {
public static final String SQL_STATE_GENERAL_ERROR = "HY000";
/**
* Create a new instance of FBResourceException
with a given
* string message and generic error code.
*
* @param reason The string message for the exception
*/
public FBResourceException(String reason) {
super(reason, SQL_STATE_GENERAL_ERROR);
}
/**
* Create a new instance of FBResourceException
with
* a message and specific error code.
*
* @param reason The string message for the exception
* @param errorCode The error code for the cause of the exception
*/
public FBResourceException(String reason, String errorCode) {
super(reason, errorCode);
}
/**
* Create a new instance of FBResourceException
with a
* generic error code that is linked to another (sub) exception.
*
* @param reason The string message for the exception
* @param original The original exception to which this instance is to
* be linked to
*/
public FBResourceException(String reason, Exception original) {
super(reason, SQL_STATE_GENERAL_ERROR);
setLinkedException(original);
}
/**
* Create a new instance of FBResourceException
with a
* generic error code that is linked to another (sub) exception.
*
* @param original The original exception to which this instance is
* to be linked to
*/
public FBResourceException(Exception original) {
super(original.getMessage(), SQL_STATE_GENERAL_ERROR);
setLinkedException(original);
}
/**
* Get message of this exception.
*
* @return combined message of this exception and original exception.
*/
public String getMessage() {
String s = super.getMessage();
if (getLinkedException() == null)
return s;
if (s == null)
return getLinkedException().getMessage();
return s + "\nReason: " + getLinkedException().getMessage();
}
/**
* Print the stack trace of this exception to STDERR
*/
public void printStackTrace() {
printStackTrace(System.err);
}
/**
* Print the stack trace of this exception to a
* given PrintStream
*
* @param s The PrintStream
to which to write the stack trace
*/
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
if (getLinkedException() != null) {
s.print("at ");
getLinkedException().printStackTrace(s);
}
}
/**
* Print the stack trace of this exception to a
* given PrintWriter
*
* @param s The PrintWriter
to which to write the stack trace
*/
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
if (getLinkedException() != null) {
s.print("at ");
getLinkedException().printStackTrace(s);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy