Java Client error handling

For Java Client applications, system methods can throw a java.rmi.RemoteException exception.

Possible errors can be grouped together as follows:

Communication Errors

The following list shows typical exceptions that might be thrown when communication problems with the system occur.

java.net.MalformedURLException
The URL is not valid.
java.net.UnknownHostException
The host name is not valid. This is the actual exception string, not the type of the Exception object.
java.net.ConnectException: Connection refused: connect
The web server not running or the port number is incorrect.
(405)Method not allowed
The URL is incomplete or inaccurate URL (typically the name of the virtual directory).
(500)Server Error
The URL is incomplete or inaccurate.
(500)Error loading module
The URL is incomplete or inaccurate.

System-specific errors

To analyze system-specific errors, use the static method getErrorDescription of the com.banter.bns.BnsErrorLookup class:
static int getErrorDescription (java.rmi.RemoteException e,
java.util.StringBuffer description)
Parameters
e
A java.rmi.RemoteException that was thrown from a method.
description
A java.util.StringBuffer for returning a textual description of the error.
Return value
The integer error code is returned, which can be compared to the error codes in class BnsErrorLookup (E_BNS_*).

Example

The following example demonstrates error handling in the system. It calls the method getAllCategories, which returns the list of knowledge base categories and handles the various possible errors.

  1. try {
  2. String[] kbCategories = bnsServer.getAllCategories (kbName);
  3. // Application code that uses kbCategories
  4. } catch (java.rmi.RemoteException e) {
  5. StringBuffer errDescription = new StringBuffer();
  6. int errNumber = BnsErrorLookup.getErrorDescription (e, errDescription);
  7. if (errNumber == BnsErrorLookup.E_BNS_SERVICE_UNAVAILABLE) {
  8. // Error handling for the case that the knowledge base is not running
  9. }
  10. else if (errNumber<0) {
  11. if (errDescription.indexOf("(403)")>=0) {
  12. // Error handling for "login failed"
  13. }
  14. else {
  15. // Error handling for other server connection errors
  16. }
  17. }
  18. else {
  19. // Error handling for other server errors
  20. }
  21. } catch (Exception e) {
  22. // Error handling
  23. }

The purpose of each section of the preceding code is shown in the following list, by line numbers:

2
Call the Server method getAllCategories
5-6
Retrieve error code and description
7-8
Error handling for the specific case of the knowledge base not running
10-15
Error handling for server connection errors
11-12
Error handling for cases where logging on fails
18-19
Error handling for other server-specific errors
21-22
Error handling for general exceptions