Suppose you have a Java class which defines a copyFile(String, String)
method:
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);
}
}
}
And suppose you wrap this in a Java stored procedure:
CREATE PROCEDURE copy_file (source_path VARCHAR2, destination_path VARCHAR2)
AS LANGUAGE JAVA
NAME 'FileSystem.copyFile(String, String)';
Now suppose you call the copy_file
stored procedure and a Java IOException
is thrown:
BEGIN
copy_file( '/some/file/that/does/not/exist.txt', '/path/to/destination.txt' );
END;
In the PL/SQL block, the error raised is:
ORA-29532 Java call terminated by uncaught Java exception
The error message also contains a description of the uncaught Exception
, but it is still an ORA-29532
. Is there a way to throw an Exception
from Java that dictates both the error code and the error message raised in PL/SQL?