[Ericsson Utvecklings AB]

11 CORBA System and User Defined Exceptions

11.1 System Exceptions

Orber, or any other ORB, may raise a System Exceptions. These exceptions contain status- and minor-fields and may not appear in the operation's raises exception IDL-definition.

11.1.1 Status Field

The status field indicates if the request was completed or not and will be assigned one of the following erlang atoms:

Table 1: System Exceptions Status
Status Description
'COMPLETED_YES' The operation was invoked on the target object but an error occured after the object replied. This occur, for example, if a server replies but Orber is not able to marshal and send the reply to the client ORB.
'COMPLETED_NO' Orber failed to invoke the operation on the target object. This occur, for example, if the object no longer exists.
'COMPLETED_MAYBE' Orber invoked the operation on the target object but an error occured and it is impossible to decide if the request really reached the object or not.

11.1.2 Minor Field

The minor field contains an integer, which the OMG initially defined to be opaque. In later CORBA specifications explicit values have been defined for the minor field, but only for a handfull of the exceptions, to enable a more exact description. Currently, Orber still uses the old settings, which is why the minor field should not be taken into consideration for exceptions raised by Orber.

11.1.3 Supported System Exceptions

The OMG CORBA specification defines the following exceptions:

11.2 User Defined Exceptions

User exceptions is defined in IDL-files and is listed in operation's raises exception listing. For example, if we have the following IDL code:

module MyModule {

  exception MyException {};
  exception MyExceptionMsg { string ExtraInfo; };

  interface MyInterface {

    void foo() 
      raises(MyException);

    void bar() 
      raises(MyException, MyExceptionMsg);

    void baz();
  };
};    
    

11.3 Throwing Exceptions

To be able to raise MyException or MyExceptionMsg exceptions, the generated MyModule.hrl must be included, and typical usage is:

-module('MyModule_MyInterface_impl').
-include("MyModule.hrl").

bar(State) ->
    case TestingSomething of
        ok ->
           {reply, ok, State};
        {error, Reason} when list(Reason) ->
           corba:raise(#'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason});
        error ->
           corba:raise(#'MyModule_MyException'{})
    end.
    

11.4 Catching Exceptions

Depending on which operation we invoke we must be able to handle:

Catching and matching exceptions can bee done in different ways:

    case catch 'MyModule_MyInterface':bar(MIReference) of
        ok ->
           %% The operation raised no exception.
           ok;
        {'EXCEPTION', #'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason}} ->
           %% If we want to log the Reason we must extract 'ExtraInfo'.
           error_logger:error_msg("Operation 'bar' raised: ~p~n", [Reason]),
           ... do something ...;
        {'EXCEPTION', E} when record(E, 'OBJECT_NOT_EXIST') ->
           ... do something ...;
        {'EXCEPTION', E} ->
           ... do something ...
    end.
    

Copyright © 1991-2002 Ericsson Utvecklings AB