For Java Client applications, system methods can throw
a java.rmi.RemoteException exception.
Possible errors can be grouped together as follows:
- Communication errors with the system. These errors are typically
returned from the network or web server.
- Specific errors that are returned from the system.
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.
- try {
- String[] kbCategories = bnsServer.getAllCategories (kbName);
- // Application code that uses kbCategories
- } catch (java.rmi.RemoteException e) {
- StringBuffer errDescription = new StringBuffer();
- int errNumber = BnsErrorLookup.getErrorDescription (e,
errDescription);
- if (errNumber == BnsErrorLookup.E_BNS_SERVICE_UNAVAILABLE)
{
- // Error handling for the case that the knowledge base
is not running
- }
- else if (errNumber<0) {
- if (errDescription.indexOf("(403)")>=0) {
- // Error handling for "login failed"
- }
- else {
- // Error handling for other server connection errors
- }
- }
- else {
- // Error handling for other server errors
- }
- } catch (Exception e) {
- // Error handling
- }
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