假设您有一个定义copyFile(String, String)
方法的 Java 类:
public class FileSystem {
public static void copyFile(String sourcePath, String destinationPath)
throws IOException
{
// ignore the fact that I'm not properly managing resources...
FileInputStream source = new FileInputStream(sourcePath);
FileOutputStream destination = new FileOutputStream(destinationPath);
copyStream(source, destination);
source.close();
destination.close();
}
private static void copyStream(InputStream source, OutputStream destination)
throws IOException
{
byte[] buffer = new byte[1024];
int length;
while ( (length = source.read(buffer)) != -1 ) {
destination.write(buffer, 0, length);
}
}
}
并假设您将其包装在 Java 存储过程中:
CREATE PROCEDURE copy_file (source_path VARCHAR2, destination_path VARCHAR2)
AS LANGUAGE JAVA
NAME 'FileSystem.copyFile(String, String)';
现在假设您调用copy_file
存储过程并IOException
抛出 Java:
BEGIN
copy_file( '/some/file/that/does/not/exist.txt', '/path/to/destination.txt' );
END;
在 PL/SQL 块中,引发的错误是:
ORA-29532 Java 调用被未捕获的 Java 异常终止
错误消息还包含未捕获的描述Exception
,但它仍然是ORA-29532
. 有没有办法Exception
从 Java 中抛出一个指示错误代码和在 PL/SQL 中引发的错误消息的方法?