Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Handling Errors | BrokerExceptions | Determining the Exception Type
 
Determining the Exception Type
You have two options for determining the exact type of exception that has been thrown.
1. You can develop your code to catch the specific types of exceptions that you expect, as shown in the following example:
. . .
BrokerClient c;
. . .
/* Create a client */
try {
c = new BrokerClient(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerClientExistsException ex) {
System.out.println("Can’t create client, already exists\n");
return;
} catch (BrokerNotRunningException ex) {
System.out.println("Can’t create client, Broker not running\n");
return;
. . .
2. You can catch the BrokerException super-class and use the instanceof operator to determine which type of exception you have caught, as shown in the following example:
. . .
BrokerClient c;
. . .
/* Create a client */
try {
c = new BrokerClient(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerException ex) {
if(ex instanceof BrokerClientExistsException) {
System.out.println("Can’t create client, already exists\n");
return;
} else if(ex instanceof BrokerNotRunningException) {
System.out.println("Can’t create client, Broker not running\n");
return;
. . .
}
. . .