J-Integra® transparently maps between COM exceptions and Java exceptions. COM components can invoke methods in Java objects using J-Integra®.
If such a method generates an exception, J-Integra® will catch the exception, and translate it to an appropriate COM exception.
Take, for example, the following Java code. Note that the 'method1' method is not particularly sound:
import java.io.*; |
This is the Visual Basic client code:
Public Sub method1(ByVal p1 As Object) |
The Visual BASIC code simply establishes an error handler, and then makes a calls into the Java object. The Java object in our example deliberately generates an exception which is caught by the Visual BASIC error handler.
The error handler displays a series of message boxes, which give information on the error:
The source J-Integra® automatically fills in the source
with the stack trace of method which
generated the error:
The description J-Integra® automatically fills in the description
with the string returned from Exception.getMessage():
We have erased the part of the stack trace showing J-Integra® internal methods.
The code J-Integra® automatically sets the code to 0x80020009, which
is COM for 'Exception occurred.':
If you wish explicitly set the error information yourself, rather than accepting J-Integra®'s default, then you can throw an instance of com.linar.jintegra.AutomationException.
If we change the Java code in the above example:
public void method1() throws com.linar.jintegra.AutomationException { |
The following message boxes get displayed, with the information that was explicitly set: