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 String
If the SQL statement contains this text, then it is never added to the SQL exception.private static final Properties
private static final DbException
private static final long
private Object
static final SQLException
Thrown when OOME exception happens on handle error insideconvert(java.lang.Throwable)
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSet the SQL statement of the given exception.static String
Builds message for an exception.static DbException
Convert a throwable to an SQL exception using the default mapping.static DbException
convertInvocation
(InvocationTargetException te, String message) Convert an InvocationTarget exception to a database exception.static DbException
convertIOException
(IOException e, String message) Convert an IO exception to a database exception.private static String
static DbException
Create a database exception for an arbitrary SQLState.static DbException
get
(int errorCode) Create a database exception for a specific error code.static DbException
Create a database exception for a specific error code.static DbException
Create a database exception for a specific error code.static DbException
Create a database exception for a specific error code.int
Get the error code.static DbException
getFileVersionError
(String dataFileName) Gets a file version exception.static RuntimeException
Gets an internal error.static RuntimeException
Gets an internal error.static DbException
getInvalidExpressionTypeException
(String param, Typed e) Gets a SQL exception meaning the type of expression is invalid or unknown.static DbException
getInvalidValueException
(String param, Object value) Gets a SQL exception meaning this value is invalid.static SQLException
getJdbcSQLException
(int errorCode) Gets the SQL exception object for a specific error code.static SQLException
getJdbcSQLException
(int errorCode, String p1) Gets the SQL exception object for a specific error code.static SQLException
getJdbcSQLException
(int errorCode, Throwable cause, String... params) Gets the SQL exception object for a specific error code.static SQLException
getJdbcSQLException
(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace) Creates a SQLException.Get the SQLException object.static DbException
getSyntaxError
(int errorCode, String sql, int index, String... params) Create a syntax error exception for a specific error code.static DbException
getSyntaxError
(String sql, int index) Create a syntax error exception.static DbException
getSyntaxError
(String sql, int index, String message) Create a syntax error exception.static DbException
getUnsupportedException
(String message) Gets a SQL exception meaning this feature is not supported.static DbException
getValueTooLongException
(String columnOrType, String value, long valueLength) Gets a SQL exception meaning this value is too long.static void
Prints up to 100 next exceptions for a specified SQL exception.static void
Prints up to 100 next exceptions for a specified SQL exception.private static String
void
static SQLException
Convert an exception to a SQL exception using the default mapping.static void
Write the exception to the driver manager log writer if configured.private static String
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
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:
-
MESSAGES
-
SQL_OOME
Thrown when OOME exception happens on handle error insideconvert(java.lang.Throwable)
. -
OOME
-
source
-
-
Constructor Details
-
DbException
-
-
Method Details
-
translate
-
quote
-
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
-
getInvalidExpressionTypeException
Gets a SQL exception meaning the type of expression is invalid or unknown.- Parameters:
param
- the name of the parametere
- the expression- 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,-1L
if 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
-
filterSQL
-
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
-