Exception.h

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

Generated on Thu Nov 9 11:54:11 2006 for TAO by doxygen 1.3.6