00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Exception.h 00006 * 00007 * $Id: Exception.h 84153 2009-01-12 18:41:55Z johnnyw $ 00008 * 00009 * This file defines way in which CORBA exceptions are reported. 00010 * 00011 * @author DOC Group at Vanderbilt U., Wash U, and UCI 00012 */ 00013 //============================================================================= 00014 00015 #ifndef TAO_EXCEPTION_H 00016 #define TAO_EXCEPTION_H 00017 00018 #include /**/ "ace/pre.h" 00019 00020 // Do not try removing this. If you remove this for subsetting lots of 00021 // things go wrong in TAO. 00022 #include "tao/orbconf.h" 00023 00024 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00025 # pragma once 00026 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00027 00028 #include /**/ "tao/TAO_Export.h" 00029 #include "tao/Basic_Types.h" 00030 #include "tao/CORBA_String.h" 00031 #include "ace/SStringfwd.h" 00032 #include "ace/iosfwd.h" 00033 #include "ace/CORBA_macros.h" 00034 00035 00036 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00037 class ACE_Allocator; 00038 ACE_END_VERSIONED_NAMESPACE_DECL 00039 00040 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00041 00042 class TAO_OutputCDR; 00043 class TAO_InputCDR; 00044 00045 // This is already done in orbconf.h. But this file is totally 00046 // decoupled from its contents that we have to do this here. Including 00047 // orbconf.h is probably going to be a overhead. 00048 #if defined (minor) 00049 #undef minor 00050 #endif /* minor */ 00051 00052 namespace CORBA 00053 { 00054 class TypeCode; 00055 typedef TypeCode * TypeCode_ptr; 00056 00057 class Environment; 00058 00059 class Any; 00060 typedef Any * Any_ptr; 00061 00062 class SystemException; 00063 00064 /** 00065 * @enum exception_type 00066 * 00067 * @brief Enumeration used to identify the type of CORBA exception. 00068 * 00069 * CORBA exceptions generally fall into two categories, user 00070 * exceptions and system exceptions. This enumeration is used when 00071 * identifying the type of CORBA exception. 00072 */ 00073 enum exception_type 00074 { 00075 NO_EXCEPTION, 00076 USER_EXCEPTION, 00077 SYSTEM_EXCEPTION 00078 }; 00079 00080 /** 00081 * @class Exception 00082 * 00083 * @brief Exception 00084 * 00085 * CORBA2-specified exception hierarchy. All exceptions have a 00086 * type (represented by a @c TypeCode) and a widely scoped type ID 00087 * (in the @c TypeCode) that are generated by any OMG-IDL compiler 00088 * and available through the Interface Repository. Think of it as a 00089 * "globally scoped" name distinguishing each exception. 00090 * 00091 * @todo According to the OMG CORBA C++ Mapping version 1.1, 00092 * the copy constructors 00093 * should be moved to "protected" section in class 00094 * declarations. Since the current MS Visual C++ 7.1 compiler 00095 * will cause some problems to TAO's exception mechanism, we 00096 * defer doing this until we drop support for MSVC++ 7.1. Maybe 00097 * there is another solution, have to test that later. 00098 */ 00099 class TAO_Export Exception 00100 { 00101 public: 00102 00103 /// Copy constructor. 00104 /** 00105 * @note This constructor should be protected, but VC7.1 at 00106 * warning level 4 complains about the inaccessible copy 00107 * constructor preventing it from being caught. However, 00108 * that probably isn't true for most cases since CORBA 00109 * exceptions are typically caught by reference, not by 00110 * copy. 00111 */ 00112 Exception (const Exception &src); 00113 00114 /// Destructor. 00115 virtual ~Exception (void); 00116 00117 // = To throw the exception (when using the standard mapping). 00118 virtual void _raise (void) const = 0; 00119 00120 // = The static narrow operations. 00121 static Exception * _downcast (Exception * x); 00122 static Exception const * _downcast (Exception const * x); 00123 00124 /// Return the repository ID of the Exception. 00125 virtual const char * _rep_id (void) const; 00126 00127 /// Return the name of the Exception. 00128 virtual const char * _name (void) const; 00129 00130 // = These are TAO-specific extensions. 00131 00132 /// Will be overridden in the concrete derived classes. 00133 virtual CORBA::TypeCode_ptr _tao_type (void) const = 0; 00134 00135 /// Print the exception to output determined by @a f. 00136 /** 00137 * @note This method is TAO-specific. 00138 */ 00139 void _tao_print_exception (const char *info, FILE *f = stdout) const; 00140 00141 #if defined (ACE_USES_WCHAR) 00142 /// ACE_WCHAR_T version of _tao_print_exception. 00143 /** 00144 * @note This method is TAO-specific. 00145 */ 00146 void _tao_print_exception (const ACE_WCHAR_T *info, FILE *f = stdout) const; 00147 #endif // ACE_USES_WCHAR 00148 00149 /// Returns a string containing information about the exception. This 00150 /// function is not CORBA compliant. 00151 virtual ACE_CString _info (void) const = 0; 00152 00153 virtual void _tao_encode (TAO_OutputCDR &cdr) const = 0; 00154 00155 virtual void _tao_decode (TAO_InputCDR &cdr) = 0; 00156 00157 /// Used in the non-copying Any insertion operator. 00158 static void _tao_any_destructor (void *); 00159 00160 /// Deep copy 00161 /** 00162 * The following operation is used in the implementation of 00163 * it performs a deep copy of the 00164 * exception, normally it is implemented as: 00165 * 00166 * <PRE> 00167 * class SomeException : public // Derives from CORBA::Exception 00168 * { 00169 * public: 00170 * virtual CORBA::Exception *_tao_duplicate (void) const 00171 * { 00172 * CORBA::Exception *result = 0; 00173 * ACE_NEW_RETURN ( 00174 * result, 00175 * SomeException (*this), 00176 * 0 00177 * ); 00178 * return result; 00179 * } 00180 * }; 00181 * </PRE> 00182 */ 00183 virtual CORBA::Exception *_tao_duplicate (void) const = 0; 00184 00185 protected: 00186 /// Default constructor. 00187 Exception (void); 00188 00189 /// Assignment operator. 00190 Exception & operator = (const Exception & src); 00191 00192 /// Construct from a respository id. 00193 Exception (const char *repository_id, const char *local_name); 00194 00195 private: 00196 /// Repository Id 00197 CORBA::String_var id_; 00198 00199 /// Local name. 00200 CORBA::String_var name_; 00201 }; 00202 00203 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY) 00204 00205 // Required by C++ mapping. 00206 TAO_Export ACE_OSTREAM_TYPE& operator<< (ACE_OSTREAM_TYPE &os, 00207 const CORBA::Exception &e); 00208 00209 TAO_Export ACE_OSTREAM_TYPE& operator<< (ACE_OSTREAM_TYPE &os, 00210 const CORBA::Exception *e); 00211 00212 #endif /* (ACE_LACKS_IOSTREAM_TOTALLY) */ 00213 } // End CORBA namespace 00214 00215 namespace TAO 00216 { 00217 /// Create a CORBA::SystemException given the interface repository ID. 00218 TAO_Export CORBA::SystemException *create_system_exception (const char *id); 00219 } 00220 00221 TAO_END_VERSIONED_NAMESPACE_DECL 00222 00223 #if defined (__ACE_INLINE__) 00224 # include "tao/Exception.inl" 00225 #endif /* __ACE_INLINE__ */ 00226 00227 #include /**/"ace/post.h" 00228 00229 #endif /* TAO_EXCEPTION_H */
1.6.1