Getting an exception value

After a method returns, the calling client program can look at the Environment structure to see if there was an exception. The Environment struct is mostly opaque, except for an exception type field named _major:

   typedef struct Environment {
      exception_type   _major;
      ...
   } Environment;

If ev._major != NO_EXCEPTION, there was an exception returned by the call. The caller can retrieve the exception name and value (passed as parameters in the somSetException call) from an Environment struct via the following functions:

string somExceptionId (Environment *ev);
somToken somExceptionValue (Environment *
ev);

The somExceptionId function returns the exception name, if any, as a string. The function somExceptionValue returns a pointer to the value of the exception, if any, contained in the exception structure. If NULL is passed as the Environment pointer in either of the above calls, an implicit call is made to somGetGlobalEnvironment.

The somExceptionFree procedure will free any memory in the Environment associated with the last exception:

void somExceptionFree (Environment *ev);

If preferred, developers can alternatively use the CORBA "exception_free" API to free the memory in an Environment structure.

Note: File "somcorba.h" (included by "som.h") provides the following aliases for strict compliance with CORBA programming interfaces:

   #ifdef CORBA_FUNCTION_NAMES
   #define exception_id    somExceptionId
   #define exception_value somExceptionValue
   #define exception_free  somExceptionFree
   #endif /* CORBA_FUNCTION_NAMES */


[Back: Setting an exception value]
[Next: Example]