Ejemplo n.º 1
0
        /// <summary>
        /// determines, which exception to return to the client based on
        /// the called method/attribute and on the Exception thrown.
        /// Make sure to return only exceptions, which are allowed for the thrower; e.g.
        /// only those specified in the interface for methods and for attributes only system exceptions.
        /// </summary>
        private Exception DetermineExceptionToThrow(Exception thrown, MethodBase thrower)
        {
            if (thrown is omg.org.CORBA.AbstractCORBASystemException)
            {
                return(thrown); // system exceptions are not wrapped or transformed
            }
            Exception exceptionToThrow;

            if ((thrower is MethodInfo) && (!((MethodInfo)thrower).IsSpecialName))   // is a normal method (i.e. no property accessor, ...)
            {
                if (ReflectionHelper.IIdlEntityType.IsAssignableFrom(thrower.DeclaringType))
                {
                    exceptionToThrow = DetermineIdlExceptionToThrow(thrown,
                                                                    (MethodInfo)thrower);
                }
                else
                {
                    if (ReflectionHelper.IsExceptionInRaiseAttributes(thrown, (MethodInfo)thrower) &&
                        (thrown is AbstractUserException))
                    {
                        exceptionToThrow = thrown; // a .NET method could also use ThrowsIdlException attribute to return non-wrapped exceptions
                    }
                    else
                    {
                        // wrap into generic user exception, because CLS to IDL gen adds this exception to
                        // all methods
                        exceptionToThrow = new GenericUserException(thrown);
                    }
                }
            }
            else if ((thrower is MethodInfo) && (((MethodInfo)thrower).IsSpecialName))     // is a special method (i.e. a property accessor, ...)
            {
                exceptionToThrow = new UNKNOWN(190, CompletionStatus.Completed_Yes);
            }
            else
            {
                // thrower == null means here, that the target method was not determined,
                // i.e. the request deserialisation was not ok
                Debug.WriteLine("target method unknown, can't determine what exception client accepts; thrown was: " +
                                thrown);
                exceptionToThrow = new UNKNOWN(201, CompletionStatus.Completed_No);
            }
            return(exceptionToThrow);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// determines, which exception to return to the client based on
 /// the called method/attribute and on the Exception thrown.
 /// Make sure to return only exceptions, which are allowed for the thrower; e.g.
 /// only those specified in the interface for methods and for attributes only system exceptions.
 /// </summary>
 private Exception DetermineExceptionToThrow(Exception thrown, MethodBase thrower) {
     if (thrown is omg.org.CORBA.AbstractCORBASystemException) {
         return thrown; // system exceptions are not wrapped or transformed
     }
     Exception exceptionToThrow;
     if ((thrower is MethodInfo) && (!((MethodInfo)thrower).IsSpecialName)) { // is a normal method (i.e. no property accessor, ...)
         if (ReflectionHelper.IIdlEntityType.IsAssignableFrom(thrower.DeclaringType)) { 
             exceptionToThrow = DetermineIdlExceptionToThrow(thrown,
                                                             (MethodInfo)thrower);
         } else {
             if (ReflectionHelper.IsExceptionInRaiseAttributes(thrown, (MethodInfo)thrower) &&
                 (thrown is AbstractUserException)) {
                 exceptionToThrow = thrown; // a .NET method could also use ThrowsIdlException attribute to return non-wrapped exceptions
             } else {
                 // wrap into generic user exception, because CLS to IDL gen adds this exception to
                 // all methods
                 exceptionToThrow = new GenericUserException(thrown);
             }
         }
     } else if ((thrower is MethodInfo) && (((MethodInfo)thrower).IsSpecialName)) { // is a special method (i.e. a property accessor, ...) 
         exceptionToThrow = new UNKNOWN(190, CompletionStatus.Completed_Yes);
     } else {
         // thrower == null means here, that the target method was not determined,
         // i.e. the request deserialisation was not ok
         Debug.WriteLine("target method unknown, can't determine what exception client accepts; thrown was: " + 
                         thrown);
         exceptionToThrow = new UNKNOWN(201, CompletionStatus.Completed_No);
     }
     return exceptionToThrow;
 }