Jump to content

SomSetException: Difference between revisions

From EDM2
Created page with "This function sets an exception value in an Environment structure. ==Syntax== <PRE> Environment *env; exception_type major; string exceptionName; somToken..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This function sets an exception value in an Environment structure.  
{{DISPLAYTITLE:somSetException}}
This function sets an exception value in an Environment structure.
 
==Syntax==
==Syntax==
<PRE>
<PRE>
Line 11: Line 13:


==Parameters==
==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.  
;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.
; 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_<exceptionName>", where <exceptionName> is the qualified (scoped) exception name. Where unambiguous, the usage bindings also define the short form "ex_<exceptionName>", where <exceptionName> 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.
; 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_<exceptionName>", where <exceptionName> is the qualified (scoped) exception name. Where unambiguous, the usage bindings also define the short form "ex_<exceptionName>", where <exceptionName> 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.  


==Return Code==
==Return Code==


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


==Example Code==
==Example Code==
Line 74: Line 73:


==Related==
==Related==
Data Structures  
;Data Structures
* Environment  
* Environment
* exception_type  
* exception_type
* string (somcorba.h)  
* string (somcorba.h)
===Methods===
;Methods
* somExceptionId  
*[[somExceptionId]]
* somExceptionValue  
*[[somExceptionValue]]
* somExceptionFree  
*[[somExceptionFree]]
* somGetGlobalEnvironmen
*[[somGetGlobalEnvironment]]


[[Category:SOM Kernel]]
[[Category:SOM function]]

Latest revision as of 05:02, 6 May 2020

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_<exceptionName>", where <exceptionName> is the qualified (scoped) exception name. Where unambiguous, the usage bindings also define the short form "ex_<exceptionName>", where <exceptionName> 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.

Return Code

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