[jOOQ/jOOQ#11304] ExecuteContext.exception() should accept null
exceptions and translate them to an unspecified DataAccessException
This commit is contained in:
parent
4993246f40
commit
d3c1229d4d
@ -291,6 +291,9 @@ public interface ExecuteContext extends Scope {
|
||||
* Override the {@link RuntimeException} being thrown.
|
||||
* <p>
|
||||
* This may have no effect, if called at the wrong moment.
|
||||
* <p>
|
||||
* If <code>null</code> is being passed, jOOQ will internally translate the
|
||||
* "unavailable" exception to an unspecified {@link DataAccessException}.
|
||||
*/
|
||||
void exception(RuntimeException e);
|
||||
|
||||
|
||||
@ -665,21 +665,21 @@ class DefaultExecuteContext implements ExecuteContext {
|
||||
|
||||
@Override
|
||||
public final void exception(RuntimeException e) {
|
||||
this.exception = e;
|
||||
this.exception = Tools.translate(sql(), e);
|
||||
|
||||
if (Boolean.TRUE.equals(settings().isDebugInfoOnStackTrace())) {
|
||||
|
||||
// [#5570] Add jOOQ version and SQL Dialect info on the stack trace
|
||||
// to help users write better bug reports.
|
||||
// See http://stackoverflow.com/q/39712695/521799
|
||||
StackTraceElement[] oldStack = e.getStackTrace();
|
||||
StackTraceElement[] oldStack = exception.getStackTrace();
|
||||
if (oldStack != null) {
|
||||
StackTraceElement[] newStack = new StackTraceElement[oldStack.length + 1];
|
||||
System.arraycopy(oldStack, 0, newStack, 1, oldStack.length);
|
||||
newStack[0] = new StackTraceElement(
|
||||
"org.jooq_" + Constants.VERSION + "." + dialect(),
|
||||
"debug", null, -1);
|
||||
e.setStackTrace(newStack);
|
||||
exception.setStackTrace(newStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2802,6 +2802,16 @@ final class Tools {
|
||||
return new DataAccessException("SQL [" + sql + "]; Unspecified SQLException");
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a {@link RuntimeException} to a {@link DataAccessException}
|
||||
*/
|
||||
static final RuntimeException translate(String sql, RuntimeException e) {
|
||||
if (e != null)
|
||||
return e;
|
||||
else
|
||||
return new DataAccessException("SQL [" + sql + "]; Unspecified RuntimeException");
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely close a statement
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user