J-Integra® transparently maps between COM exceptions and Java exceptions.
When a Java client invokes a method in a COM component, that component may raise an exception.
COM Exceptions have an associated error number, a source, and a description.
In Visual BASIC, an exception can be raised like this:
Public Sub errorMethod() |
In Visual C++, an exception can be raised like this:
AfxThrowOleDispatchException(0, "I am sorry Dave, I can't do that..."); |
When a COM component throws an exception, an instance of com.linar.jintegra.AutomationException is thrown in the Java client.
The AutomationException class exposes methods to obtain the error number, source and description of the COM exception that was thrown.
import com.linar.jintegra.AuthInfo; |
The result of running the example:
If you don't like the idea of having to deal with the AutomationException class, then you can catch java.io.IOException instead, since AutomationException derives from IOException. In this way you can reduce the dependancy of your code on COM related classes, at the expense of not being able to access the error code, description and source.