Top Description Fields Constructors Methods
org.h2.message

public Class DbException

extends RuntimeException
Class Inheritance
Static Imports
org.h2.api.ErrorCode.*

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

Field Summary

Modifier and TypeField and Description
public static final String
HIDE_SQL

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
public static final SQLException
SQL_OOME

Thrown when OOME exception happens on handle error inside convert(java.lang.Throwable).

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public DbException

Returns:

the exception
addSQL
(String
the SQL statement
sql
)

Set the SQL statement of the given exception.

public static String

Returns:

message
buildMessageForException
(JdbcException
exception
e
)

Builds message for an exception.

public static DbException

Returns:

the exception object
convert
(Throwable
the root cause
e
)

Convert a throwable to an SQL exception using the default mapping.

public static DbException

Returns:

the database exception object
convertInvocation
(InvocationTargetException
the root cause
te
,
String
the added message or null
message
)

Convert an InvocationTarget exception to a database exception.

public static DbException

Returns:

the database exception object
convertIOException
(IOException
the root cause
e
,
String
the message or null
message
)

Convert an IO exception to a database exception.

private static String
public static DbException

Returns:

the exception
fromUser
(String
the state to use
sqlstate
,
String
the message to use
message
)

Create a database exception for an arbitrary SQLState.

public static DbException

Returns:

the exception
get
(int
the error code
errorCode
)

Create a database exception for a specific error code.

public static DbException

Returns:

the exception
get
(int
the error code
errorCode
,
String
the first parameter of the message
p1
)

Create a database exception for a specific error code.

public static DbException

Returns:

the exception
get
(int
the error code
errorCode
,
Throwable
the cause of the exception
cause
,
String...
the list of parameters of the message
params
)

Create a database exception for a specific error code.

public static DbException

Returns:

the exception
get
(int
the error code
errorCode
,
String...
the list of parameters of the message
params
)

Create a database exception for a specific error code.

public int

Returns:

the error code
getErrorCode
()

Get the error code.

public static DbException

Returns:

the exception
getFileVersionError
(String
the name of the database
dataFileName
)

Gets a file version exception.

public static RuntimeException

Returns:

the RuntimeException object
getInternalError
(String
the message
s
)

Gets an internal error.

public static RuntimeException

Returns:

the RuntimeException object
getInternalError
()

Gets an internal error.

public static DbException

Returns:

the exception
getInvalidValueException
(String
the name of the parameter
param
,
Object
the value passed
value
)

Gets a SQL exception meaning this value is invalid.

public static DbException

Returns:

the exception
getInvalidValueException
(Throwable
the cause of the exception
cause
,
String
the name of the parameter
param
,
Object
the value passed
value
)

Gets a SQL exception meaning this value is invalid.

public static SQLException

Returns:

the SQLException object
getJdbcSQLException
(int
the error code
errorCode
)

Gets the SQL exception object for a specific error code.

public static SQLException

Returns:

the SQLException object
getJdbcSQLException
(int
the error code
errorCode
,
String
the first parameter of the message
p1
)

Gets the SQL exception object for a specific error code.

public static SQLException

Returns:

the SQLException object
getJdbcSQLException
(int
the error code
errorCode
,
Throwable
the cause of the exception
cause
,
String...
the list of parameters of the message
params
)

Gets the SQL exception object for a specific error code.

public static SQLException

Returns:

the SQLException object
getJdbcSQLException
(String
the reason
message
,
String
the SQL statement
sql
,
String
the SQL state
state
,
int
the error code
errorCode
,
Throwable
the exception that was the reason for this exception
cause
,
String
the stack trace
stackTrace
)

Creates a SQLException.

public Object
public SQLException

Returns:

the exception
getSQLException
()

Get the SQLException object.

public static DbException

Returns:

the exception
getSyntaxError
(String
the SQL statement
sql
,
int
the position of the error in the SQL statement
index
)

Create a syntax error exception.

public static DbException

Returns:

the exception
getSyntaxError
(String
the SQL statement
sql
,
int
the position of the error in the SQL statement
index
,
String
the message
message
)

Create a syntax error exception.

public static DbException

Returns:

the exception
getSyntaxError
(int
the error code
errorCode
,
String
the SQL statement
sql
,
int
the position of the error in the SQL statement
index
,
String...
the list of parameters of the message
params
)

Create a syntax error exception for a specific error code.

public static DbException

Returns:

the exception
getUnsupportedException
(String
what exactly is not supported
message
)

Gets a SQL exception meaning this feature is not supported.

public static DbException

Returns:

the exception
getValueTooLongException
(String
column with data type or data type name
columnOrType
,
String
string representation of value, will be truncated to 80 characters
value
,
long
the actual length of value, -1L if unknown
valueLength
)

Gets a SQL exception meaning this value is too long.

public static void
printNextExceptions(SQLException
SQL exception
e
,
PrintWriter
print writer
s
)

Prints up to 100 next exceptions for a specified SQL exception.

public static void
printNextExceptions(SQLException
SQL exception
e
,
PrintStream
print stream
s
)

Prints up to 100 next exceptions for a specified SQL exception.

private static String
public void
setSource(Object source)

public static SQLException

Returns:

the SQL exception object
toSQLException
(Throwable
the root cause
e
)

Convert an exception to a SQL exception using the default mapping.

public static void
traceThrowable(Throwable
the exception
e
)

Write the exception to the driver manager log writer if configured.

private static String
translate(String key, String... params)

Field Detail

HIDE_SQLback to summary
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.

MESSAGESback to summary
private static final Properties MESSAGES
OOMEback to summary
private static final DbException OOME
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.RuntimeException.serialVersionUID.

sourceback to summary
private Object source
SQL_OOMEback to summary
public static final SQLException SQL_OOME

Thrown when OOME exception happens on handle error inside convert(java.lang.Throwable).

Constructor Detail

DbExceptionback to summary
private DbException(SQLException e)

Method Detail

addSQLback to summary
public DbException addSQL(String sql)

Set the SQL statement of the given exception. This method may create a new object.

Parameters
sql:String

the SQL statement

Returns:DbException

the exception

buildMessageForExceptionback to summary
public static String buildMessageForException(JdbcException e)

Builds message for an exception.

Parameters
e:JdbcException

exception

Returns:String

message

convertback to summary
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:Throwable

the root cause

Returns:DbException

the exception object

convertInvocationback to summary
public static DbException convertInvocation(InvocationTargetException te, String message)

Convert an InvocationTarget exception to a database exception.

Parameters
te:InvocationTargetException

the root cause

message:String

the added message or null

Returns:DbException

the database exception object

convertIOExceptionback to summary
public static DbException convertIOException(IOException e, String message)

Convert an IO exception to a database exception.

Parameters
e:IOException

the root cause

message:String

the message or null

Returns:DbException

the database exception object

filterSQLback to summary
private static String filterSQL(String sql)
fromUserback to summary
public static DbException fromUser(String sqlstate, String message)

Create a database exception for an arbitrary SQLState.

Parameters
sqlstate:String

the state to use

message:String

the message to use

Returns:DbException

the exception

getback to summary
public static DbException get(int errorCode)

Create a database exception for a specific error code.

Parameters
errorCode:int

the error code

Returns:DbException

the exception

getback to summary
public static DbException get(int errorCode, String p1)

Create a database exception for a specific error code.

Parameters
errorCode:int

the error code

p1:String

the first parameter of the message

Returns:DbException

the exception

getback to summary
public static DbException get(int errorCode, Throwable cause, String... params)

Create a database exception for a specific error code.

Parameters
errorCode:int

the error code

cause:Throwable

the cause of the exception

params:String[]

the list of parameters of the message

Returns:DbException

the exception

getback to summary
public static DbException get(int errorCode, String... params)

Create a database exception for a specific error code.

Parameters
errorCode:int

the error code

params:String[]

the list of parameters of the message

Returns:DbException

the exception

getErrorCodeback to summary
public int getErrorCode()

Get the error code.

Returns:int

the error code

getFileVersionErrorback to summary
public static DbException getFileVersionError(String dataFileName)

Gets a file version exception.

Parameters
dataFileName:String

the name of the database

Returns:DbException

the exception

getInternalErrorback to summary
public static RuntimeException getInternalError(String s)

Gets an internal error.

Parameters
s:String

the message

Returns:RuntimeException

the RuntimeException object

getInternalErrorback to summary
public static RuntimeException getInternalError()

Gets an internal error.

Returns:RuntimeException

the RuntimeException object

getInvalidValueExceptionback to summary
public static DbException getInvalidValueException(String param, Object value)

Gets a SQL exception meaning this value is invalid.

Parameters
param:String

the name of the parameter

value:Object

the value passed

Returns:DbException

the exception

getInvalidValueExceptionback to summary
public static DbException getInvalidValueException(Throwable cause, String param, Object value)

Gets a SQL exception meaning this value is invalid.

Parameters
cause:Throwable

the cause of the exception

param:String

the name of the parameter

value:Object

the value passed

Returns:DbException

the exception

getJdbcSQLExceptionback to summary
public static SQLException getJdbcSQLException(int errorCode)

Gets the SQL exception object for a specific error code.

Parameters
errorCode:int

the error code

Returns:SQLException

the SQLException object

getJdbcSQLExceptionback to summary
public static SQLException getJdbcSQLException(int errorCode, String p1)

Gets the SQL exception object for a specific error code.

Parameters
errorCode:int

the error code

p1:String

the first parameter of the message

Returns:SQLException

the SQLException object

getJdbcSQLExceptionback to summary
public static SQLException getJdbcSQLException(int errorCode, Throwable cause, String... params)

Gets the SQL exception object for a specific error code.

Parameters
errorCode:int

the error code

cause:Throwable

the cause of the exception

params:String[]

the list of parameters of the message

Returns:SQLException

the SQLException object

getJdbcSQLExceptionback to summary
public static SQLException getJdbcSQLException(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace)

Creates a SQLException.

Parameters
message:String

the reason

sql:String

the SQL statement

state:String

the SQL state

errorCode:int

the error code

cause:Throwable

the exception that was the reason for this exception

stackTrace:String

the stack trace

Returns:SQLException

the SQLException object

getSourceback to summary
public Object getSource()
getSQLExceptionback to summary
public SQLException getSQLException()

Get the SQLException object.

Returns:SQLException

the exception

getSyntaxErrorback to summary
public static DbException getSyntaxError(String sql, int index)

Create a syntax error exception.

Parameters
sql:String

the SQL statement

index:int

the position of the error in the SQL statement

Returns:DbException

the exception

getSyntaxErrorback to summary
public static DbException getSyntaxError(String sql, int index, String message)

Create a syntax error exception.

Parameters
sql:String

the SQL statement

index:int

the position of the error in the SQL statement

message:String

the message

Returns:DbException

the exception

getSyntaxErrorback to summary
public static DbException getSyntaxError(int errorCode, String sql, int index, String... params)

Create a syntax error exception for a specific error code.

Parameters
errorCode:int

the error code

sql:String

the SQL statement

index:int

the position of the error in the SQL statement

params:String[]

the list of parameters of the message

Returns:DbException

the exception

getUnsupportedExceptionback to summary
public static DbException getUnsupportedException(String message)

Gets a SQL exception meaning this feature is not supported.

Parameters
message:String

what exactly is not supported

Returns:DbException

the exception

getValueTooLongExceptionback to summary
public static DbException getValueTooLongException(String columnOrType, String value, long valueLength)

Gets a SQL exception meaning this value is too long.

Parameters
columnOrType:String

column with data type or data type name

value:String

string representation of value, will be truncated to 80 characters

valueLength:long

the actual length of value, -1L if unknown

Returns:DbException

the exception

printNextExceptionsback to summary
public static void printNextExceptions(SQLException e, PrintWriter s)

Prints up to 100 next exceptions for a specified SQL exception.

Parameters
e:SQLException

SQL exception

s:PrintWriter

print writer

printNextExceptionsback to summary
public static void printNextExceptions(SQLException e, PrintStream s)

Prints up to 100 next exceptions for a specified SQL exception.

Parameters
e:SQLException

SQL exception

s:PrintStream

print stream

quoteback to summary
private static String quote(String s)
setSourceback to summary
public void setSource(Object source)
toSQLExceptionback to summary
public static SQLException toSQLException(Throwable e)

Convert an exception to a SQL exception using the default mapping.

Parameters
e:Throwable

the root cause

Returns:SQLException

the SQL exception object

traceThrowableback to summary
public static void traceThrowable(Throwable e)

Write the exception to the driver manager log writer if configured.

Parameters
e:Throwable

the exception

translateback to summary
private static String translate(String key, String... params)