The exceptions in the CORBA model include both system and user exceptions. The CORBA specification defines a set of system exceptions that can be raised when errors occur in the processing of a client request. Also, system exceptions are raised in the case of communication failures. System exceptions can be raised at any time and they do not need to be declared in the interface.System exceptions are usually raised by the VisiBroker ORB, though it is possible for object implementations to raise them through interceptors discussed in “Using VisiBroker Interceptors”. When the VisiBroker ORB raises a SystemException, one of the CORBA-defined error conditions is displayed as shown below.
module Bank {
interface Account {
exception AccountFrozen {
};
float balance() raises(AccountFrozen);
};
};The AccountImpl object must be modified to use the exception by raising the exception under the appropriate error conditions.public class AccountImpl extends Bank.AccountPOA {
public AccountImpl(float balance) {
_balance = balance;
}
public float balance() throws AccountFrozen {
if (_balance < 50) {
throws AccountFrozen();
} else {
return _balance;
}
private float _balance;
}When an object implementation raises an exception, the VisiBroker ORB is responsible for reflecting the exception to your client program. Checking for a UserException is similar to checking for a SystemException. To modify the account client program to catch the AccountFrozen exception, make modifications to the code as shown below.You can associate values with user exceptions. The code sample below shows how to modify the IDL interface specification to add a reason code to the AccountFrozen user exception. The object implementation that raises the exception is responsible for setting the reason code. The reason code is printed automatically when the exception is put on the output stream.// Bank.idl
module Bank {
interface Account {
exception AccountFrozen {
int reason;
};
float balance() raises(AccountFrozen);
};
};