public final class FbExceptionBuilder
extends java.lang.Object
This class is not thread-safe.
Constructor and Description |
---|
FbExceptionBuilder() |
Modifier and Type | Method and Description |
---|---|
FbExceptionBuilder |
cause(java.lang.Throwable cause)
Sets the cause of the current exception.
|
FbExceptionBuilder |
exception(int errorCode)
The (next) exception is an exception.
|
static FbExceptionBuilder |
forException(int errorCode)
Creates an exception builder with the specified error code.
|
static FbExceptionBuilder |
forWarning(int errorCode)
Creates an exception builder for a warning with the specified error code.
|
boolean |
isEmpty() |
FbExceptionBuilder |
messageParameter(int parameter)
Adds an integer message parameter for the exception message.
|
FbExceptionBuilder |
messageParameter(java.lang.String parameter)
Adds a string message parameter for the exception message.
|
FbExceptionBuilder |
nonTransientConnectionException(int errorCode)
Force the next exception to be a
SQLNonTransientConnectionException . |
FbExceptionBuilder |
nonTransientException(int errorCode)
Force the next exception to be a
SQLNonTransientException . |
FbExceptionBuilder |
sqlState(java.lang.String sqlState)
Sets the SQL state.
|
FbExceptionBuilder |
timeoutException(int errorCode)
Force the next exception to be a
SQLTimeoutException . |
java.sql.SQLException |
toFlatSQLException()
Converts the builder to a single SQLException instance with a single exception message.
|
<T extends java.sql.SQLException> |
toFlatSQLException(java.lang.Class<T> type)
Converts the builder to the appropriate SQLException instance and casts to the specified type T.
|
java.sql.SQLException |
toSQLException()
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional
exceptions).
|
<T extends java.sql.SQLException> |
toSQLException(java.lang.Class<T> type)
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional
exceptions) and casts to the specified type T.
|
java.lang.String |
toString() |
FbExceptionBuilder |
warning(int errorCode)
The (next) exception is a warning.
|
public FbExceptionBuilder exception(int errorCode)
This method and related methods can be called multiple times. This builder might produce a chained exception, but could also merge exceptions depending on the error code and other rules internal to this builder.
errorCode
- The Firebird error codewarning(int)
public static FbExceptionBuilder forException(int errorCode)
Equivalent to calling: new FbExceptionBuilder().error(errorCode);
errorCode
- The Firebird error codepublic static FbExceptionBuilder forWarning(int errorCode)
Equivalent to calling: new FbExceptionBuilder().warning(errorCode);
errorCode
- The Firebird error codepublic FbExceptionBuilder warning(int errorCode)
errorCode
- The Firebird error codeexception(int)
public FbExceptionBuilder timeoutException(int errorCode)
SQLTimeoutException
.errorCode
- The Firebird error codeexception(int)
public FbExceptionBuilder nonTransientException(int errorCode)
SQLNonTransientException
.errorCode
- The Firebird error codeexception(int)
public FbExceptionBuilder nonTransientConnectionException(int errorCode)
SQLNonTransientConnectionException
.errorCode
- The Firebird error codeexception(int)
public FbExceptionBuilder messageParameter(int parameter)
parameter
- Message parameterpublic FbExceptionBuilder messageParameter(java.lang.String parameter)
parameter
- Message parameterpublic FbExceptionBuilder sqlState(java.lang.String sqlState)
SQL State is usually derived from the errorCode. Use of this method is optional.
sqlState
- SQL State valuepublic FbExceptionBuilder cause(java.lang.Throwable cause)
cause
- Throwable with the causepublic java.sql.SQLException toSQLException()
When returning exception information from the status vector, it is advisable to use toFlatSQLException()
as this applies some heuristics to get more specific error codes and flattens the message into a single
exception.
If isEmpty()
returns false
, then this will throw an IllegalStateException
.
toFlatSQLException()
public java.sql.SQLException toFlatSQLException()
This method attempts to assign the most specific error code and SQL state to the returned exception.
The cause of the returned exception is set to an instance of FBSQLExceptionInfo
which contains the separate items obtained from the status vector. These items are chained together using
the SQLException chain.
If isEmpty()
returns false
, then this will throw an IllegalStateException
.
FBSQLExceptionInfo
public <T extends java.sql.SQLException> T toSQLException(java.lang.Class<T> type) throws java.lang.ClassCastException
T
- Expected exception typetype
- Class of type Tjava.lang.ClassCastException
- If the first exception created with this builder is not of the specified typetoSQLException()
public <T extends java.sql.SQLException> T toFlatSQLException(java.lang.Class<T> type) throws java.lang.ClassCastException
T
- Expected exception typetype
- Class of type Tjava.lang.ClassCastException
- If the first exception created with this builder is not of the specified typetoFlatSQLException()
public boolean isEmpty()
true
if this builder contains exception information, false
otherwisepublic java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2001-2021 Jaybird (Firebird JDBC/JCA) team. All rights reserved.