Package org.h2.message
Class DbException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.h2.message.DbException
- All Implemented Interfaces:
Serializable
This exception wraps a checked exception.
It is used in methods where checked exceptions are not supported,
for example in a Comparator.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIf the SQL statement contains this text, then it is never added to the SQL exception.static final SQLExceptionThrown when OOME exception happens on handle error insideconvert(java.lang.Throwable). -
Method Summary
Modifier and TypeMethodDescriptionSet the SQL statement of the given exception.static StringBuilds message for an exception.static DbExceptionConvert a throwable to an SQL exception using the default mapping.static DbExceptionconvertInvocation(InvocationTargetException te, String message) Convert an InvocationTarget exception to a database exception.static DbExceptionconvertIOException(IOException e, String message) Convert an IO exception to a database exception.static DbExceptionCreate a database exception for an arbitrary SQLState.static DbExceptionget(int errorCode) Create a database exception for a specific error code.static DbExceptionCreate a database exception for a specific error code.static DbExceptionCreate a database exception for a specific error code.static DbExceptionCreate a database exception for a specific error code.intGet the error code.static DbExceptiongetFileVersionError(String dataFileName) Gets a file version exception.static RuntimeExceptionGets an internal error.static RuntimeExceptionGets an internal error.static DbExceptiongetInvalidValueException(String param, Object value) Gets a SQL exception meaning this value is invalid.static DbExceptiongetInvalidValueException(Throwable cause, String param, Object value) Gets a SQL exception meaning this value is invalid.static SQLExceptiongetJdbcSQLException(int errorCode) Gets the SQL exception object for a specific error code.static SQLExceptiongetJdbcSQLException(int errorCode, String p1) Gets the SQL exception object for a specific error code.static SQLExceptiongetJdbcSQLException(int errorCode, Throwable cause, String... params) Gets the SQL exception object for a specific error code.static SQLExceptiongetJdbcSQLException(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace) Creates a SQLException.Get the SQLException object.static DbExceptiongetSyntaxError(int errorCode, String sql, int index, String... params) Create a syntax error exception for a specific error code.static DbExceptiongetSyntaxError(String sql, int index) Create a syntax error exception.static DbExceptiongetSyntaxError(String sql, int index, String message) Create a syntax error exception.static DbExceptiongetUnsupportedException(String message) Gets a SQL exception meaning this feature is not supported.static DbExceptiongetValueTooLongException(String columnOrType, String value, long valueLength) Gets a SQL exception meaning this value is too long.static voidPrints up to 100 next exceptions for a specified SQL exception.static voidPrints up to 100 next exceptions for a specified SQL exception.voidstatic SQLExceptionConvert an exception to a SQL exception using the default mapping.static voidWrite the exception to the driver manager log writer if configured.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
HIDE_SQL
If the SQL statement contains this text, then it is never added to the SQL exception. Hiding the SQL statement may be important if it contains a passwords, such as a CREATE LINKED TABLE statement.- See Also:
-
SQL_OOME
Thrown when OOME exception happens on handle error insideconvert(java.lang.Throwable).
-
-
Method Details
-
getSQLException
Get the SQLException object.- Returns:
- the exception
-
getErrorCode
public int getErrorCode()Get the error code.- Returns:
- the error code
-
addSQL
Set the SQL statement of the given exception. This method may create a new object.- Parameters:
sql- the SQL statement- Returns:
- the exception
-
get
Create a database exception for a specific error code.- Parameters:
errorCode- the error code- Returns:
- the exception
-
get
Create a database exception for a specific error code.- Parameters:
errorCode- the error codep1- the first parameter of the message- Returns:
- the exception
-
get
Create a database exception for a specific error code.- Parameters:
errorCode- the error codecause- the cause of the exceptionparams- the list of parameters of the message- Returns:
- the exception
-
get
Create a database exception for a specific error code.- Parameters:
errorCode- the error codeparams- the list of parameters of the message- Returns:
- the exception
-
fromUser
Create a database exception for an arbitrary SQLState.- Parameters:
sqlstate- the state to usemessage- the message to use- Returns:
- the exception
-
getSyntaxError
Create a syntax error exception.- Parameters:
sql- the SQL statementindex- the position of the error in the SQL statement- Returns:
- the exception
-
getSyntaxError
Create a syntax error exception.- Parameters:
sql- the SQL statementindex- the position of the error in the SQL statementmessage- the message- Returns:
- the exception
-
getSyntaxError
Create a syntax error exception for a specific error code.- Parameters:
errorCode- the error codesql- the SQL statementindex- the position of the error in the SQL statementparams- the list of parameters of the message- Returns:
- the exception
-
getUnsupportedException
Gets a SQL exception meaning this feature is not supported.- Parameters:
message- what exactly is not supported- Returns:
- the exception
-
getInvalidValueException
Gets a SQL exception meaning this value is invalid.- Parameters:
param- the name of the parametervalue- the value passed- Returns:
- the exception
-
getInvalidValueException
Gets a SQL exception meaning this value is invalid.- Parameters:
cause- the cause of the exceptionparam- the name of the parametervalue- the value passed- Returns:
- the exception
-
getValueTooLongException
public static DbException getValueTooLongException(String columnOrType, String value, long valueLength) Gets a SQL exception meaning this value is too long.- Parameters:
columnOrType- column with data type or data type namevalue- string representation of value, will be truncated to 80 charactersvalueLength- the actual length of value,-1Lif unknown- Returns:
- the exception
-
getFileVersionError
Gets a file version exception.- Parameters:
dataFileName- the name of the database- Returns:
- the exception
-
getInternalError
Gets an internal error.- Parameters:
s- the message- Returns:
- the RuntimeException object
-
getInternalError
Gets an internal error.- Returns:
- the RuntimeException object
-
toSQLException
Convert an exception to a SQL exception using the default mapping.- Parameters:
e- the root cause- Returns:
- the SQL exception object
-
convert
Convert a throwable to an SQL exception using the default mapping. All errors except the following are re-thrown: StackOverflowError, LinkageError.- Parameters:
e- the root cause- Returns:
- the exception object
-
convertInvocation
Convert an InvocationTarget exception to a database exception.- Parameters:
te- the root causemessage- the added message or null- Returns:
- the database exception object
-
convertIOException
Convert an IO exception to a database exception.- Parameters:
e- the root causemessage- the message or null- Returns:
- the database exception object
-
getJdbcSQLException
Gets the SQL exception object for a specific error code.- Parameters:
errorCode- the error code- Returns:
- the SQLException object
-
getJdbcSQLException
Gets the SQL exception object for a specific error code.- Parameters:
errorCode- the error codep1- the first parameter of the message- Returns:
- the SQLException object
-
getJdbcSQLException
Gets the SQL exception object for a specific error code.- Parameters:
errorCode- the error codecause- the cause of the exceptionparams- the list of parameters of the message- Returns:
- the SQLException object
-
getJdbcSQLException
public static SQLException getJdbcSQLException(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace) Creates a SQLException.- Parameters:
message- the reasonsql- the SQL statementstate- the SQL stateerrorCode- the error codecause- the exception that was the reason for this exceptionstackTrace- the stack trace- Returns:
- the SQLException object
-
buildMessageForException
Builds message for an exception.- Parameters:
e- exception- Returns:
- message
-
printNextExceptions
Prints up to 100 next exceptions for a specified SQL exception.- Parameters:
e- SQL exceptions- print writer
-
printNextExceptions
Prints up to 100 next exceptions for a specified SQL exception.- Parameters:
e- SQL exceptions- print stream
-
getSource
-
setSource
-
traceThrowable
Write the exception to the driver manager log writer if configured.- Parameters:
e- the exception
-