SomSetException

This function sets an exception value in an Environment structure.

Syntax
 Environment      *env; exception_type   major; string           exceptionName; somToken         params;

somSetException(env, major, exceptionName, params); 

Parameters

 * env (Environment *) : A pointer to the Environment structure in which to set the exception. This value must be either NULL or a value formerly obtained from the function somGetGlobalEnvironment.


 * major (exception_type) : major An integer representing the type of exception to set.


 * exceptionName (string) : The qualified name of the exception to set. The SOM Compiler defines, in the header files it generates for an interface, a constant whose value is the qualified name of each exception defined within the interface. This constant has the name "ex_", where  is the qualified (scoped) exception name. Where unambiguous, the usage bindings also define the short form "ex_", where  is unqualified.


 * params (somToken) : A pointer to an initialized exception structure value. No copy is made of this structure; hence, the caller cannot free it. The somExceptionFree function should be used to free the Environment structure that contains it.

Remarks
This function sets an exception value in an Environment structure.

Example Code
 /* IDL declaration of class X: */ interface X : SOMObject { exception OUCH {long code1; long code2; }; void foo(in long arg) raises (OUCH); }; /* implementation of foo method */ SOM_Scope void SOMLINK foo(X somSelf, Environment *ev, long arg) { X_OUCH *exception_params; /* X_OUCH struct is defined in X's usage bindings   */

if (arg > 5) /* then this is a very bad error */ {     exception_params = (X_OUCH*)SOM_Malloc(sizeof(X_OUCH)); exception_params->code1 = arg; exception_params->code2 = arg-5; somSetException (ev, USER_EXCEPTION, ex_X_OUCH, exception_params); /* the Environment ev now contains an X_OUCH exception, with * the specified exception_params struct. The constant * ex_X_OUCH is defined in foo.h. Note that exception_params * must be malloced. */     return; } ... } main {  Environment *ev; X x;

somEnvironmentNew; x = Xnew; ev = somGetGlobalEnvironment; X_foo(x, ev, 23); if (ev->_major != NO_EXCEPTION) { printf("foo exception = %s\n", somExceptionId(ev)); printf("code1 = %d\n",  ((X_OUCH*) somExceptionValue(ev))->code1); /* finished handling exception. */  /* free the copied id and the original X_OUCH structure: */ somExceptionFree(ev); } ... } 

Related
Data Structures
 * Environment
 * exception_type
 * string (somcorba.h)

Methods

 * somExceptionId
 * somExceptionValue
 * somExceptionFree
 * somGetGlobalEnvironment