Recall Subsection 10.2.3 discussed issues associated
with the fact that SIDL supports exception interfaces while Java does not.
In the following example, derived from regression tests, a getFibi
method takes an integer argument and can throw one of two exceptions
specified as SIDL exception interfaces NegativeValueException
and TooDeepException.
try { fib.getFibi(-1); } catch (NegativeValueException.Wrapper ex) { System.err.println(ex.getNote()); } catch (TooDeepException.Wrapper ex) { System.err.println(ex.getNote()); } catch (java.lang.Exception ex) { if (((sidl.BaseInterface)ex).isType("sidl.SIDLException")) { System.err.println("Unexpected SIDL Exception thrown"); } else { System.err.println("Unexpected and unknown exception thrown"); } }
Since the two exception types are specified as interfaces, the code to trap each must reference their Wrapper classes. Hence, the use of each class's fully qualified name in the catch clauses.
The example also illustrates another option that is generally available for distinguishing between exception types. That is, the body of the final catch includes a call to the isType() method, which is used to check the exception against a named type. In this example, however, SIDL can cast between the two interfaces, so isType() would return true regardless of the the type of the exception instance.