[Ericsson 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 operations 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 occurred 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 occurred 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 (VMCID), which is related to a more specific reason why an invocation failed. The function orber:exception_info/1 can be used to map the minor code to a string. Note, for VMCID:s not assigned by the OMG or Orber, the documentation for that particular ORB must be consulted.

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 operations raises exception listing. For example, if we have the following IDL code:

module MyModule {

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

  interface MyInterface {

    void foo() 

    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:


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

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.
        {'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 ...

orber 3.6.11
Copyright © 1991-2009 Ericsson AB