Errors can occur when PL/SQL attempts to call a Java method. This is not an exception thrown by the Java method, but an error condition resulting from the attempt to call the method. The following are possible errors that can occur:
When an error of this type occurs, it indicates that an error has happened
within the Oracle Forms Server runtime process as it has attempted to perform
an operation with the JVM. This causes a PL/SQL exception of type ORA_JAVA.JAVA_ERROR
to be thrown, indicating that an unexpected result occurred. This PL/SQL exception
can be detected using the standard PL/SQL exception handling mechanism. If you
wish to obtain more information about which exact error occurred, the ORA_JAVA.LAST_ERROR
function will return the runtime error information as a PL/SQL VARCHAR2
.
Note that if you do not add explicit exception handlers to your code, then these Oracle errors might be thrown instead of a named exception:
ORA_JAVA.JAVA_ERROR
ORA_JAVA.EXCEPTION_THROWN
For the following example, the java.lang.StringBuffer
class has been imported.
DECLARE
buffer ORA_JAVA.JOBJECT;
newBuffer ORA_JAVA.JOBJECT;
BEGIN
-- This will intentionally raise an error because
-- an instance of a StringBuffer was not created
-- with buffer := StringBuffer.new;
newBuffer := StringBuffer.append(buffer,'Value to Append');
EXCEPTION
WHEN ORA_JAVA.JAVA_ERROR THEN
-- In this case, the error would be
-- Argument 1 can not be null
message(ORA_JAVA.LAST_ERROR);
--Clean up
ORA_JAVA.CLEAR_ERROR;
END;