Categories

Duncan Mills

Syndicate this blog

Exception Handling in Forms / Java Integration Code

It's a common issue when people are trying to call out to Java from Forms that an ORA-105101 error gets raised in Forms. This error is actually the PL/SQL exception ORA_JAVA.EXCEPTION_THROWN, and you guessed it, indicates that the Java code being called is itself throwing an exception.
As a matter of course any Java code called from Oracle Forms in this way should include the correct handlers to catch this.

  1. Use the Java importer to import java.lang.Exception into the Form.
    This will create a PL/SQL package called Exception_ Note the trailing underscore which is appended because of course Exception is a PL/SQL keyword in it's own right.
  2. Then wrap your calls to the imported code with the following code block
    declare
      raisedException ORA_JAVA.JOBJECT;
      --
      -- Your declarations here
      --
    begin
      --
      -- Your calls here
     --
    exception
      --check for ORA-105101
      when ORA_JAVA.EXCEPTION_THROWN then
         raisedException  := ORA_JAVA.LAST_EXCEPTION;
         message("Java Exception : " 
          || Exception_.getMessage(raisedException);
          ORA_JAVA.CLEAR_EXCEPTION;
      end; 

Comments:

Comment from: Sandra Muller [Visitor] · http://blogs.oracle.com/jheadstart
Some additional information that might be helpful for others who try this as well:
  • To get this to work I had to import java.lang.Exception by typing in the full class name (it was not available in the tree browser). Before importing, I also had to change the options: check the 'Include inherited methods/fields' otherwise the getMessage procedure will not be available.
  • Also, the last statement in the exception handler should be slightly different (single quotes and an extra closing bracket): message('Java Exception : ' || Exception_.getMessage(raisedException)); ORA_JAVA.CLEAR_EXCEPTION;
  • See also Jan Carlin's blog post at http://groundside.com/blog/JanCarlin.php?title=extracting_a_stack_trace_from_a_java_exc&more=1&c.
Permalink 01/10/07 @ 16:55

Comments are closed for this post.