提交 7f048fc0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved error message when an non-SQL-exception occurred in a user defined function.

上级 d80a84bd
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Unsupported compression options: {0} 90102=Unsupported compression options: {0}
90103=Unsupported compression algorithm: {0} 90103=Unsupported compression algorithm: {0}
90104=Compression error 90104=Compression error
90105=Exception calling user-defined function 90105=Exception calling user-defined function: {0}
90106=Cannot truncate {0} 90106=Cannot truncate {0}
90107=Cannot drop {0} because {1} depends on it 90107=Cannot drop {0} because {1} depends on it
90108=Out of memory. 90108=Out of memory.
......
...@@ -1493,7 +1493,7 @@ public class ErrorCode { ...@@ -1493,7 +1493,7 @@ public class ErrorCode {
* CALL SYS_PROP(NULL); * CALL SYS_PROP(NULL);
* </pre> * </pre>
*/ */
public static final int EXCEPTION_IN_FUNCTION = 90105; public static final int EXCEPTION_IN_FUNCTION_1 = 90105;
/** /**
* The error with code <code>90106</code> is thrown when * The error with code <code>90106</code> is thrown when
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.engine; package org.h2.engine;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.sql.Connection; import java.sql.Connection;
...@@ -371,6 +372,15 @@ public class FunctionAlias extends DbObjectBase { ...@@ -371,6 +372,15 @@ public class FunctionAlias extends DbObjectBase {
if (returnValue == null) { if (returnValue == null) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
} catch (InvocationTargetException e) {
StatementBuilder buff = new StatementBuilder(method.getName());
buff.append('(');
for (Object o : params) {
buff.appendExceptFirst(", ");
buff.append(o == null ? "null" : o.toString());
}
buff.append(')');
throw DbException.convertInvocation(e, buff.toString());
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
} }
......
...@@ -266,12 +266,7 @@ public class DbException extends RuntimeException { ...@@ -266,12 +266,7 @@ public class DbException extends RuntimeException {
} else if (e instanceof SQLException) { } else if (e instanceof SQLException) {
return new DbException((SQLException) e); return new DbException((SQLException) e);
} else if (e instanceof InvocationTargetException) { } else if (e instanceof InvocationTargetException) {
InvocationTargetException te = (InvocationTargetException) e; return convertInvocation((InvocationTargetException) e, null);
Throwable t = te.getTargetException();
if (t instanceof SQLException || t instanceof DbException) {
return convert(t);
}
return get(ErrorCode.EXCEPTION_IN_FUNCTION, t);
} else if (e instanceof IOException) { } else if (e instanceof IOException) {
return get(ErrorCode.IO_EXCEPTION_1, e, e.toString()); return get(ErrorCode.IO_EXCEPTION_1, e, e.toString());
} else if (e instanceof OutOfMemoryError) { } else if (e instanceof OutOfMemoryError) {
...@@ -284,6 +279,15 @@ public class DbException extends RuntimeException { ...@@ -284,6 +279,15 @@ public class DbException extends RuntimeException {
return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); return get(ErrorCode.GENERAL_ERROR_1, e, e.toString());
} }
public static DbException convertInvocation(InvocationTargetException te, String message) {
Throwable t = te.getTargetException();
if (t instanceof SQLException || t instanceof DbException) {
return convert(t);
}
message = message == null ? t.getMessage() : message + ": " + t.getMessage();
return get(ErrorCode.EXCEPTION_IN_FUNCTION_1, t, message);
}
/** /**
* Convert an IO exception to a SQL exception. * Convert an IO exception to a SQL exception.
* *
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Datenkompressions-Option nicht unterstützt: {0} 90102=Datenkompressions-Option nicht unterstützt: {0}
90103=Datenkompressions-Algorithmus nicht unterstützt: {0} 90103=Datenkompressions-Algorithmus nicht unterstützt: {0}
90104=Datenkompressions Fehler 90104=Datenkompressions Fehler
90105=Fehler beim Aufruf eine benutzerdefinierten Funktion 90105=Fehler beim Aufruf eine benutzerdefinierten Funktion: {0}
90106=Kann {0} nicht zurücksetzen per TRUNCATE 90106=Kann {0} nicht zurücksetzen per TRUNCATE
90107=Kann {0} nicht löschen weil {1} davon abhängt 90107=Kann {0} nicht löschen weil {1} davon abhängt
90108=Nicht genug Hauptspeicher. 90108=Nicht genug Hauptspeicher.
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Unsupported compression options: {0} 90102=Unsupported compression options: {0}
90103=Unsupported compression algorithm: {0} 90103=Unsupported compression algorithm: {0}
90104=Compression error 90104=Compression error
90105=Exception calling user-defined function 90105=Exception calling user-defined function: {0}
90106=Cannot truncate {0} 90106=Cannot truncate {0}
90107=Cannot drop {0} because {1} depends on it 90107=Cannot drop {0} because {1} depends on it
90108=Out of memory. 90108=Out of memory.
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Opciones de compresión No soportadas: {0} 90102=Opciones de compresión No soportadas: {0}
90103=Algoritmo de compresión No soportado: {0} 90103=Algoritmo de compresión No soportado: {0}
90104=Error de Compresión 90104=Error de Compresión
90105=Exception llamando a una función definida por el usuario 90105=Exception llamando a una función definida por el usuario: {0}
90106=Imposible truncar {0} 90106=Imposible truncar {0}
90107=Imposible eliminar {0} debido a que {1} depende de él. 90107=Imposible eliminar {0} debido a que {1} depende de él.
90108=Memoria Insuficiente - Out of memory. Tamaño: {0} 90108=Memoria Insuficiente - Out of memory. Tamaño: {0}
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=未サポートの圧縮オプション: {0} 90102=未サポートの圧縮オプション: {0}
90103=未サポートの圧縮アルゴリズム: {0} 90103=未サポートの圧縮アルゴリズム: {0}
90104=圧縮エラー 90104=圧縮エラー
90105=ユーザ定義関数を実行中に例外が発生しました 90105=ユーザ定義関数を実行中に例外が発生しました: {0}
90106={0} を空にできません 90106={0} を空にできません
90107={1} が依存しているため、{0} をドロップすることはできません 90107={1} が依存しているため、{0} をドロップすることはできません
90108=メモリが不足しています 90108=メモリが不足しています
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Nie wspierana opcja kompresji: {0} 90102=Nie wspierana opcja kompresji: {0}
90103=Nie wspierany algorytm kompresji: {0} 90103=Nie wspierany algorytm kompresji: {0}
90104=Blad kompresji 90104=Blad kompresji
90105=Wyjatek wywoluje funkcje uzytkownika 90105=Wyjatek wywoluje funkcje uzytkownika: {0}
90106=Nie mozna obciac {0} 90106=Nie mozna obciac {0}
90107=Nie mozna skasowac {0} poniewaz zalezy od {1} 90107=Nie mozna skasowac {0} poniewaz zalezy od {1}
90108=#Out of memory. 90108=#Out of memory.
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Não é suportado as opções de compressão: {0} 90102=Não é suportado as opções de compressão: {0}
90103=Não é suportado o algorítimo de compressão: {0} 90103=Não é suportado o algorítimo de compressão: {0}
90104=Erro na compressão 90104=Erro na compressão
90105=Exceção na chamada da função definida pelo usuário 90105=Exceção na chamada da função definida pelo usuário: {0}
90106=Não pode fazer o truncate {0} 90106=Não pode fazer o truncate {0}
90107=Não pode apagar {0} por que depende de {1} 90107=Não pode apagar {0} por que depende de {1}
90108=#Out of memory. 90108=#Out of memory.
......
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
90102=Неподдерживаемые опции сжатия: {0} 90102=Неподдерживаемые опции сжатия: {0}
90103=Неподдерживаемый алгоритм сжатия: {0} 90103=Неподдерживаемый алгоритм сжатия: {0}
90104=Ошибка сжатия 90104=Ошибка сжатия
90105=Ошибка при вызове пользовательской функции 90105=Ошибка при вызове пользовательской функции: {0}
90106=Невозможно очистить {0} 90106=Невозможно очистить {0}
90107=Невозможно удалить {0}, пока существует зависимый объект {1} 90107=Невозможно удалить {0}, пока существует зависимый объект {1}
90108=Ошибка нехватки памяти 90108=Ошибка нехватки памяти
......
...@@ -21,4 +21,4 @@ org.h2.tools.Script.main=Options are case sensitive. Supported options are\:\n[- ...@@ -21,4 +21,4 @@ org.h2.tools.Script.main=Options are case sensitive. Supported options are\:\n[-
org.h2.tools.Server=Starts the H2 Console (web-) server, TCP, and PG server. org.h2.tools.Server=Starts the H2 Console (web-) server, TCP, and PG server.
org.h2.tools.Server.main=When running without options, -tcp, -web, -browser and -pg are started.\nOptions are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-web] Start the web server with the H2 Console\n[-webAllowOthers] Allow other computers to connect - see below\n[-webDaemon] Use a daemon thread\n[-webPort <port>] The port (default\: 8082)\n[-webSSL] Use encrypted (HTTPS) connections\n[-browser] Start a browser connecting to the web server\n[-tcp] Start the TCP server\n[-tcpAllowOthers] Allow other computers to connect - see below\n[-tcpDaemon] Use a daemon thread\n[-tcpPort <port>] The port (default\: 9092)\n[-tcpSSL] Use encrypted (SSL) connections\n[-tcpPassword <pwd>] The password for shutting down a TCP server\n[-tcpShutdown "<url>"] Stop the TCP server; example\: tcp\://localhost\n[-tcpShutdownForce] Do not wait until all connections are closed\n[-pg] Start the PG server\n[-pgAllowOthers] Allow other computers to connect - see below\n[-pgDaemon] Use a daemon thread\n[-pgPort <port>] The port (default\: 5435)\n[-baseDir <dir>] The base directory for H2 databases (all servers)\n[-ifExists] Only existing databases may be opened (all servers)\n[-trace] Print additional trace information (all servers)\nThe options -xAllowOthers are potentially risky.\nFor details, see Advanced Topics / Protection against Remote Access. org.h2.tools.Server.main=When running without options, -tcp, -web, -browser and -pg are started.\nOptions are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-web] Start the web server with the H2 Console\n[-webAllowOthers] Allow other computers to connect - see below\n[-webDaemon] Use a daemon thread\n[-webPort <port>] The port (default\: 8082)\n[-webSSL] Use encrypted (HTTPS) connections\n[-browser] Start a browser connecting to the web server\n[-tcp] Start the TCP server\n[-tcpAllowOthers] Allow other computers to connect - see below\n[-tcpDaemon] Use a daemon thread\n[-tcpPort <port>] The port (default\: 9092)\n[-tcpSSL] Use encrypted (SSL) connections\n[-tcpPassword <pwd>] The password for shutting down a TCP server\n[-tcpShutdown "<url>"] Stop the TCP server; example\: tcp\://localhost\n[-tcpShutdownForce] Do not wait until all connections are closed\n[-pg] Start the PG server\n[-pgAllowOthers] Allow other computers to connect - see below\n[-pgDaemon] Use a daemon thread\n[-pgPort <port>] The port (default\: 5435)\n[-baseDir <dir>] The base directory for H2 databases (all servers)\n[-ifExists] Only existing databases may be opened (all servers)\n[-trace] Print additional trace information (all servers)\nThe options -xAllowOthers are potentially risky.\nFor details, see Advanced Topics / Protection against Remote Access.
org.h2.tools.Shell=Interactive command line tool to access a database using JDBC. org.h2.tools.Shell=Interactive command line tool to access a database using JDBC.
org.h2.tools.Shell.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-url "<url>"] The database URL (jdbc\:h2\:...)\n[-user <user>] The user name\n[-password <pwd>] The password\n[-driver <class>] The JDBC driver class to use (not required in most cases)\nIf special characters don't work as expected, you may need to use\n -Dfile.encoding\=UTF-8 (Mac OS X) or CP850 (Windows). org.h2.tools.Shell.main=Options are case sensitive. Supported options are\:\n[-help] or [-?] Print the list of options\n[-url "<url>"] The database URL (jdbc\:h2\:...)\n[-user <user>] The user name\n[-password <pwd>] The password\n[-driver <class>] The JDBC driver class to use (not required in most cases)\n[-sql "<statements>"] Execute the SQL statements and exit\nIf special characters don't work as expected, you may need to use\n -Dfile.encoding\=UTF-8 (Mac OS X) or CP850 (Windows).
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论