Error Handling


One nice feature of Java is the enforced error-handling capability provided by the exception mechanism. The SmartSockets Java Class Library fully utilizes exceptions, throwing them to indicate many types of error conditions. As illustrated by the example sending and receiving programs above, an important part of any SmartSockets Java program is appropriate error-handling procedures in the catch blocks following code that may throw an exception. The online class library documentation details the exceptions that each method can throw, as well as explanations of common error conditions.

Specific classes of exceptions should be caught when possible, instead of using the blanket Exception class. All SmartSockets exceptions are inherited from the TipcException class, which is itself derived from Exception. As an example of the appropriate way to catch exceptions, see these examples:

try { 
  srv.send(a_message); 
  // possibly more code 
} catch (TipcException err) { 
  // handle the error here 
} 

The above specifies the exact exception that may be thrown, TipcException. This is preferred over the more generic code:

try { 
  srv.send(a_message); 
  // possibly more code 
} catch (Exception err) { 
  // handle error 
} 

Using the more specific exception object makes debugging easier and more succinct, because other code in the try block is likely to generate different specific exceptions.


TIBCO SmartSockets™ Java Library User’s Guide and Tutorial
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com