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`

public class DbException extends RuntimeException
This exception wraps a checked exception. It is used in methods where checked exceptions are not supported, for example in a Comparator.

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`HIDE_SQL`
If the SQL statement contains this text, then it is never added to the SQL exception.
`static final SQLException`
`SQL_OOME`
Thrown when OOME exception happens on handle error inside `convert(java.lang.Throwable)`.

## Method Summary

Modifier and Type
Method
Description
`DbException`
`addSQL(String sql)`
Set the SQL statement of the given exception.
`static String`
`buildMessageForException(JdbcException e)`
Builds message for an exception.
`static DbException`
`convert(Throwable e)`
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.
`static DbException`
`fromUser(String sqlstate, String message)`
Create a database exception for an arbitrary SQLState.
`static DbException`
`get(int errorCode)`
Create a database exception for a specific error code.
`static DbException`
`get(int errorCode, String p1)`
Create a database exception for a specific error code.
`static DbException`
`get(int errorCode, String... params)`
Create a database exception for a specific error code.
`static DbException`
`get(int errorCode, Throwable cause, String... params)`
Create a database exception for a specific error code.
`int`
`getErrorCode()`
Get the error code.
`static DbException`
`getFileVersionError(String dataFileName)`
Gets a file version exception.
`static RuntimeException`
`getInternalError()`
Gets an internal error.
`static RuntimeException`
`getInternalError(String s)`
Gets an internal error.
`static DbException`
`getInvalidValueException(String param, Object value)`
Gets a SQL exception meaning this value is invalid.
`static DbException`
`getInvalidValueException(Throwable cause, 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.
`Object`
`getSource()`
`SQLException`
`getSQLException()`
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`
`printNextExceptions(SQLException e, PrintStream s)`
Prints up to 100 next exceptions for a specified SQL exception.
`static void`
`printNextExceptions(SQLException e, PrintWriter s)`
Prints up to 100 next exceptions for a specified SQL exception.
`void`
`setSource(Object source)`
`static SQLException`
`toSQLException(Throwable e)`
Convert an exception to a SQL exception using the default mapping.
`static void`
`traceThrowable(Throwable e)`
Write 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### HIDE_SQL

public static final String 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:
  - Constant Field Values

### SQL_OOME

public static final SQLException SQL_OOME
Thrown when OOME exception happens on handle error inside `convert(java.lang.Throwable)`.

## Method Details

### getSQLException

public SQLException getSQLException()
Get the SQLException object.

Returns:
  the exception

### getErrorCode

public int getErrorCode()
Get the error code.

Returns:
  the error code

### addSQL

public DbException addSQL(String sql)
Set the SQL statement of the given exception. This method may create a new object.

Parameters:
  `sql` - the SQL statement
Returns:
  the exception

### get

public static DbException get(int errorCode)
Create a database exception for a specific error code.

Parameters:
  `errorCode` - the error code
Returns:
  the exception

### get

public static DbException get(int errorCode, String p1)
Create a database exception for a specific error code.

Parameters:
  `errorCode` - the error code
  `p1` - the first parameter of the message
Returns:
  the exception

### get

public static DbException get(int errorCode, Throwable cause, String... params)
Create a database exception for a specific error code.

Parameters:
  `errorCode` - the error code
  `cause` - the cause of the exception
  `params` - the list of parameters of the message
Returns:
  the exception

### get

public static DbException get(int errorCode, String... params)
Create a database exception for a specific error code.

Parameters:
  `errorCode` - the error code
  `params` - the list of parameters of the message
Returns:
  the exception

### fromUser

public static DbException fromUser(String sqlstate, String message)
Create a database exception for an arbitrary SQLState.

Parameters:
  `sqlstate` - the state to use
  `message` - the message to use
Returns:
  the exception

### getSyntaxError

public static DbException getSyntaxError(String sql, int index)
Create a syntax error exception.

Parameters:
  `sql` - the SQL statement
  `index` - the position of the error in the SQL statement
Returns:
  the exception

### getSyntaxError

public static DbException getSyntaxError(String sql, int index, String message)
Create a syntax error exception.

Parameters:
  `sql` - the SQL statement
  `index` - the position of the error in the SQL statement
  `message` - the message
Returns:
  the exception

### getSyntaxError

public static DbException getSyntaxError(int errorCode, String sql, int index, String... params)
Create a syntax error exception for a specific error code.

Parameters:
  `errorCode` - the error code
  `sql` - the SQL statement
  `index` - the position of the error in the SQL statement
  `params` - the list of parameters of the message
Returns:
  the exception

### getUnsupportedException

public static DbException getUnsupportedException(String message)
Gets a SQL exception meaning this feature is not supported.

Parameters:
  `message` - what exactly is not supported
Returns:
  the exception

### getInvalidValueException

public static DbException getInvalidValueException(String param, Object value)
Gets a SQL exception meaning this value is invalid.

Parameters:
  `param` - the name of the parameter
  `value` - the value passed
Returns:
  the exception

### getInvalidValueException

public static DbException getInvalidValueException(Throwable cause, String param, Object value)
Gets a SQL exception meaning this value is invalid.

Parameters:
  `cause` - the cause of the exception
  `param` - the name of the parameter
  `value` - 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 name
  `value` - string representation of value, will be truncated to 80 characters
  `valueLength` - the actual length of value, `-1L` if unknown
Returns:
  the exception

### getFileVersionError

public static DbException getFileVersionError(String dataFileName)
Gets a file version exception.

Parameters:
  `dataFileName` - the name of the database
Returns:
  the exception

### getInternalError

public static RuntimeException getInternalError(String s)
Gets an internal error.

Parameters:
  `s` - the message
Returns:
  the RuntimeException object

### getInternalError

public static RuntimeException getInternalError()
Gets an internal error.

Returns:
  the RuntimeException object

### toSQLException

public static SQLException toSQLException(Throwable e)
Convert an exception to a SQL exception using the default mapping.

Parameters:
  `e` - the root cause
Returns:
  the SQL exception object

### convert

public static DbException convert(Throwable e)
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

public static DbException convertInvocation(InvocationTargetException te, String message)
Convert an InvocationTarget exception to a database exception.

Parameters:
  `te` - the root cause
  `message` - the added message or null
Returns:
  the database exception object

### convertIOException

public static DbException convertIOException(IOException e, String message)
Convert an IO exception to a database exception.

Parameters:
  `e` - the root cause
  `message` - the message or null
Returns:
  the database exception object

### getJdbcSQLException

public static SQLException getJdbcSQLException(int errorCode)
Gets the SQL exception object for a specific error code.

Parameters:
  `errorCode` - the error code
Returns:
  the SQLException object

### getJdbcSQLException

public static SQLException getJdbcSQLException(int errorCode, String p1)
Gets the SQL exception object for a specific error code.

Parameters:
  `errorCode` - the error code
  `p1` - the first parameter of the message
Returns:
  the SQLException object

### getJdbcSQLException

public static SQLException getJdbcSQLException(int errorCode, Throwable cause, String... params)
Gets the SQL exception object for a specific error code.

Parameters:
  `errorCode` - the error code
  `cause` - the cause of the exception
  `params` - 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 reason
  `sql` - the SQL statement
  `state` - the SQL state
  `errorCode` - the error code
  `cause` - the exception that was the reason for this exception
  `stackTrace` - the stack trace
Returns:
  the SQLException object

### buildMessageForException

public static String buildMessageForException(JdbcException e)
Builds message for an exception.

Parameters:
  `e` - exception
Returns:
  message

### printNextExceptions

public static void printNextExceptions(SQLException e, PrintWriter s)
Prints up to 100 next exceptions for a specified SQL exception.

Parameters:
  `e` - SQL exception
  `s` - print writer

### printNextExceptions

public static void printNextExceptions(SQLException e, PrintStream s)
Prints up to 100 next exceptions for a specified SQL exception.

Parameters:
  `e` - SQL exception
  `s` - print stream

### getSource

public Object getSource()

### setSource

public void setSource(Object source)

### traceThrowable

public static void traceThrowable(Throwable e)
Write the exception to the driver manager log writer if configured.

Parameters:
  `e` - the exception