Class FbExceptionBuilder
This class is not thread-safe.
- Author:
- Mark Rotteveel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the cause of the current exception.exception(int errorCode) The (next) exception is an exception.static FbExceptionBuilderforException(int errorCode) Creates an exception builder with the specified error code.static FbExceptionBuilderforWarning(int errorCode) Creates an exception builder for a warning with the specified error code.booleanisEmpty()messageParameter(int parameter) Adds an integer message parameter for the exception message.messageParameter(String parameter) Adds a string message parameter for the exception message.nonTransientConnectionException(int errorCode) Force the next exception to be aSQLNonTransientConnectionException.nonTransientException(int errorCode) Force the next exception to be aSQLNonTransientException.Sets the SQL state.timeoutException(int errorCode) Force the next exception to be aSQLTimeoutException.Converts the builder to a single SQLException instance with a single exception message.<T extends SQLException>
TtoFlatSQLException(Class<T> type) Converts the builder to the appropriate SQLException instance and casts to the specified type T.Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions).<T extends SQLException>
TtoSQLException(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.toString()warning(int errorCode) The (next) exception is a warning.
-
Constructor Details
-
FbExceptionBuilder
public FbExceptionBuilder()
-
-
Method Details
-
exception
The (next) exception is an exception.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.
- Parameters:
errorCode- The Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
forException
Creates an exception builder with the specified error code.Equivalent to calling:
new FbExceptionBuilder().error(errorCode);- Parameters:
errorCode- The Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
-
forWarning
Creates an exception builder for a warning with the specified error code.Equivalent to calling:
new FbExceptionBuilder().warning(errorCode);- Parameters:
errorCode- The Firebird error code- Returns:
- FbExceptionBuilder initialized with the specified error code
-
warning
The (next) exception is a warning.- Parameters:
errorCode- The Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
timeoutException
Force the next exception to be aSQLTimeoutException.- Parameters:
errorCode- The Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
nonTransientException
Force the next exception to be aSQLNonTransientException.- Parameters:
errorCode- The Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
nonTransientConnectionException
Force the next exception to be aSQLNonTransientConnectionException.- Parameters:
errorCode- The Firebird error code- Returns:
- this FbExceptionBuilder
- See Also:
-
messageParameter
Adds an integer message parameter for the exception message.- Parameters:
parameter- Message parameter- Returns:
- this FbExceptionBuilder
-
messageParameter
Adds a string message parameter for the exception message.- Parameters:
parameter- Message parameter- Returns:
- this FbExceptionBuilder
-
sqlState
Sets the SQL state. Overriding the value derived from the Firebird error code.SQL State is usually derived from the errorCode. Use of this method is optional.
- Parameters:
sqlState- SQL State value- Returns:
- this FbExceptionBuilder
-
cause
Sets the cause of the current exception.- Parameters:
cause- Throwable with the cause- Returns:
- this FbExceptionBuilder
-
toSQLException
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions).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()returnsfalse, then this will throw anIllegalStateException.- Returns:
- SQLException object
- See Also:
-
toFlatSQLException
Converts the builder to a single SQLException instance with a single exception message.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
FBSQLExceptionInfowhich contains the separate items obtained from the status vector. These items are chained together using the SQLException chain.If
isEmpty()returnsfalse, then this will throw anIllegalStateException.- Returns:
- SQLException object
- See Also:
-
toSQLException
Converts the builder to the appropriate SQLException instance (optionally with a chain of additional exceptions) and casts to the specified type T.- Type Parameters:
T- Expected exception type- Parameters:
type- Class of type T- Returns:
- SQLException of type T
- Throws:
ClassCastException- If the first exception created with this builder is not of the specified type- See Also:
-
toFlatSQLException
Converts the builder to the appropriate SQLException instance and casts to the specified type T.- Type Parameters:
T- Expected exception type- Parameters:
type- Class of type T- Returns:
- SQLException of type T
- Throws:
ClassCastException- If the first exception created with this builder is not of the specified type- See Also:
-
isEmpty
public boolean isEmpty()- Returns:
trueif this builder contains exception information,falseotherwise
-
toString
-