Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Exception.h

Go to the documentation of this file.
00001 // This may look like C, but it's really -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Exception.h
00006  *
00007  *  $Id: Exception.h,v 1.1.1.4 2003/02/21 18:36:44 chad Exp $
00008  *
00009  *   This file defines way in which CORBA exceptions are reported.
00010  *
00011  *
00012  *  @author  Copyright 1994-1995 by Sun Microsystems Inc.
00013  */
00014 //=============================================================================
00015 
00016 #ifndef TAO_EXCEPTION_H
00017 #define TAO_EXCEPTION_H
00018 #include "ace/pre.h"
00019 
00020 #include "tao/corbafwd.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "ace/SString.h"
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 /* TAO_HAS_EXCEPTIONS */
00034 
00035 #include "ace/SString.h"
00036 
00037 class CORBA_Any;
00038 class TAO_OutputCDR;
00039 class TAO_InputCDR;
00040 
00041 /**
00042  * @class CORBA_Exception
00043  *
00044  * @brief CORBA_Exception
00045  *
00046  * CORBA2-specified exception hierarchy.  All exceptions have a
00047  * type (represented by a TypeCode) and a widely scoped type ID
00048  * (in the TypeCode) that generated by any OMG-IDL compiler and
00049  * available through the Interface Repositories.  Think of it as a
00050  * "globally scoped" name distinguishing each exception.
00051  */
00052 class TAO_Export CORBA_Exception
00053 {
00054 public:
00055   // = Initialization and termination methods.
00056 
00057   /// Copy constructor.
00058   CORBA_Exception (const CORBA_Exception &src);
00059 
00060   /// Assignment operator.
00061   CORBA_Exception &operator = (const CORBA_Exception &src);
00062 
00063   /// Destructor.
00064   virtual ~CORBA_Exception (void);
00065 
00066   // = To throw the exception (when using the standard mapping).
00067   virtual void _raise (void) = 0;
00068 
00069   // = The static narrow operation.
00070   static CORBA_Exception *_downcast (CORBA_Exception *x);
00071 
00072   // = These are TAO-specific extensions.
00073 
00074   /// Return the repository ID of the Exception.
00075   const char *_rep_id (void) const;
00076 
00077   /// Return the name of the Exception.
00078   const char *_name (void) const;
00079 
00080   /// Will be overridden in the concrete derived classes.
00081   virtual CORBA::TypeCode_ptr _type (void) const;
00082 
00083   // = To implement the narrow method.
00084   virtual int _is_a (const char* repository_id) const;
00085 
00086   /// Constructor from a respository id.
00087   CORBA_Exception (const char *repository_id,
00088                    const char *local_name);
00089 
00090   /// Print the exception <ex> to output determined by <f>.  This
00091   /// function is not CORBA compliant.
00092   void _tao_print_exception (const char *info,
00093                              FILE *f = stdout) const;
00094 
00095 #if defined (ACE_USES_WCHAR)
00096   /// ACE_WCHAR_T version of _tao_print_exception.
00097   void _tao_print_exception (const ACE_WCHAR_T *info,
00098                              FILE *f = stdout) const;
00099 #endif  // ACE_USES_WCHAR
00100 
00101   /// Returns a string containing information about the exception. This
00102   /// function is not CORBA compliant.
00103   virtual ACE_CString _info (void) const = 0;
00104 
00105   virtual void _tao_encode (TAO_OutputCDR &cdr
00106                             ACE_ENV_ARG_DECL_NOT_USED) const = 0;
00107   virtual void _tao_decode (TAO_InputCDR &cdr
00108                             ACE_ENV_ARG_DECL_NOT_USED) = 0;
00109 
00110   /// Used in the non-copying Any insertion operator.
00111   static void _tao_any_destructor (void *);
00112 
00113   /// Deep copy
00114   /**
00115    * The following operation is used in the implementation of
00116    * it performs a deep copy of the
00117    * exception, normally it is implemented as:
00118    *
00119    * <PRE>
00120    * class SomeException : public // Derives from CORBA_Exception
00121    * {
00122    * public:
00123    *   virtual CORBA_Exception *_tao_duplicate (void) const
00124    *   {
00125    *     return new SomeException (*this);
00126    *   }
00127    * };
00128    * </PRE>
00129    */
00130   virtual CORBA_Exception *_tao_duplicate (void) const = 0;
00131 
00132 protected:
00133   CORBA_Exception (void);
00134   // Default constructor is protected.
00135 
00136 private:
00137   /// Storage of our repository id and local name.
00138   char *id_;
00139   char *name_;
00140 };
00141 
00142 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00143 
00144 // Convenient ostream operator.
00145 TAO_Export ostream& operator<< (ostream &os,
00146                                 const CORBA_Exception &e);
00147 
00148 #endif /* (ACE_LACKS_IOSTREAM_TOTALLY) */
00149 
00150 /**
00151  * @class CORBA_UserException
00152  *
00153  * @brief User exceptions are those defined by application developers
00154  * using OMG-IDL.
00155  */
00156 class TAO_Export CORBA_UserException : public CORBA_Exception
00157 {
00158 public:
00159   // = Initialization and termination methods.
00160 
00161   /// Copy constructor.
00162   CORBA_UserException (const CORBA_UserException &src);
00163 
00164   /// Destructor.
00165   ~CORBA_UserException (void);
00166 
00167   /// Assignment operator.
00168   CORBA_UserException &operator= (const CORBA_UserException &src);
00169 
00170   /// The narrow operation.
00171   static CORBA_UserException *_downcast (CORBA_Exception *exception);
00172 
00173   // = TAO specific extension.
00174 
00175   /// Constructor from a repository id.
00176   CORBA_UserException (const char *repository_id,
00177                        const char *local_name);
00178 
00179   virtual int _is_a (const char *interface_id) const;
00180 
00181   // Used for narrowing
00182 
00183   /// Returns a string containing information about the exception. This
00184   /// function is not CORBA compliant.
00185   virtual ACE_CString _info (void) const;
00186 
00187   //protected:
00188   /// Default constructor.
00189   CORBA_UserException (void);
00190 };
00191 
00192 /**
00193  * @class CORBA_SystemException
00194  *
00195  * @brief CORBA_SystemException
00196  *
00197  * System exceptions are those defined in the CORBA spec; OMG-IDL
00198  * defines these.
00199  */
00200 class TAO_Export CORBA_SystemException : public CORBA_Exception
00201 {
00202 public:
00203   // = Initialization and termination methods.
00204 
00205   /// Default constructtor
00206   CORBA_SystemException (void);
00207 
00208   /// Copy constructor.
00209   CORBA_SystemException (const CORBA_SystemException &src);
00210 
00211   /// Destructor.
00212   ~CORBA_SystemException (void);
00213 
00214   /// Assignment operator.
00215   CORBA_SystemException &operator= (const CORBA_SystemException &src);
00216 
00217   /// Get the minor status.
00218   CORBA::ULong minor (void) const;
00219 
00220   /// Set the minor status.
00221   void minor (CORBA::ULong m);
00222 
00223   /// Get the completion status.
00224   CORBA::CompletionStatus completed (void) const;
00225 
00226   /// Set the operation completion status.
00227   void completed (CORBA::CompletionStatus c);
00228 
00229   /// Narrow to a SystemException.
00230   static CORBA_SystemException *_downcast (CORBA_Exception *exception);
00231 
00232   // = TAO-specific extension.
00233 
00234   /// Helper for the _downcast operation.
00235   virtual int _is_a (const char *type_id) const;
00236 
00237   /// Print the system exception <ex> to output determined by f.  This
00238   /// function is not CORBA compliant.
00239   void _tao_print_system_exception (FILE *f = stdout) const;
00240 
00241   /// Returns a string containing information about the exception. This
00242   /// function is not CORBA compliant.
00243   virtual ACE_CString _info (void) const;
00244 
00245   virtual void _tao_encode (TAO_OutputCDR &cdr
00246                             ACE_ENV_ARG_DECL_NOT_USED) const;
00247   virtual void _tao_decode (TAO_InputCDR &cdr
00248                             ACE_ENV_ARG_DECL_NOT_USED);
00249 
00250   /// Helper to create a minor status value.
00251   static CORBA::ULong _tao_minor_code (u_int location,
00252                                        int errno_value);
00253 
00254   /// Helper to translate a platform-specific errno to a TAO errno
00255   /// value.
00256   static CORBA::ULong _tao_errno (int errno_value);
00257 
00258 protected:
00259 
00260   /// Constructor using a repository id.
00261   CORBA_SystemException (const char *repository_id,
00262                          const char *local_name,
00263                          CORBA::ULong code,
00264                          CORBA::CompletionStatus completed);
00265 
00266   /// Return the exception description associated with the given OMG
00267   /// minor code.
00268   static const char *_tao_get_omg_exception_description (
00269       const CORBA::SystemException &exc,
00270       CORBA::ULong minor_code
00271     );
00272 
00273 private:
00274   /// Minor code.
00275   CORBA::ULong minor_;
00276 
00277   /// Completion status.
00278   CORBA::CompletionStatus completed_;
00279 
00280 };
00281 
00282 // Declarations for all of the CORBA standard exceptions.
00283 //
00284 // @@ - shouldn't have a default minor code, at least for code that's
00285 // inside the ORB.  All minor codes should be symbolically catalogued.
00286 
00287 #define TAO_SYSTEM_EXCEPTION(name) \
00288 class TAO_Export CORBA_ ## name : public CORBA_SystemException { \
00289 public: \
00290   CORBA_ ## name (void); \
00291   CORBA_ ## name (CORBA::ULong code, \
00292                   CORBA::CompletionStatus completed) \
00293     : CORBA_SystemException ("IDL:omg.org/CORBA/" #name ":1.0", \
00294                              #name, \
00295                              code, \
00296                              completed) \
00297     { } \
00298   static CORBA_##name * _downcast (CORBA_Exception* exception); \
00299   virtual int _is_a (const char* type_id) const; \
00300   virtual void _raise (void); \
00301   virtual CORBA::TypeCode_ptr _type (void) const; \
00302   static void _tao_any_destructor (void*); \
00303   virtual CORBA_Exception *_tao_duplicate (void) const; \
00304 }; \
00305 TAO_Export void operator<<= (CORBA::Any &, const CORBA_##name &); \
00306 TAO_Export void operator<<= (CORBA::Any &, CORBA_##name *); \
00307 TAO_Export CORBA::Boolean operator>>= (const CORBA::Any &, \
00308                                        const CORBA_##name *&)
00309 
00310 
00311 TAO_SYSTEM_EXCEPTION(UNKNOWN);          // the unknown exception
00312 TAO_SYSTEM_EXCEPTION(BAD_PARAM);        // an invalid parameter was passed
00313 TAO_SYSTEM_EXCEPTION(NO_MEMORY);        // memory allocation failure
00314 TAO_SYSTEM_EXCEPTION(IMP_LIMIT);        // violated implementation limit
00315 TAO_SYSTEM_EXCEPTION(COMM_FAILURE);     // communication failure
00316 TAO_SYSTEM_EXCEPTION(INV_OBJREF);       // invalid object reference
00317 TAO_SYSTEM_EXCEPTION(OBJECT_NOT_EXIST); // no such object
00318 TAO_SYSTEM_EXCEPTION(NO_PERMISSION);    // no permission for operation
00319 TAO_SYSTEM_EXCEPTION(INTERNAL);         // ORB internal error
00320 TAO_SYSTEM_EXCEPTION(MARSHAL);          // error marshaling param/result
00321 TAO_SYSTEM_EXCEPTION(INITIALIZE);       // ORB initialization failure
00322 TAO_SYSTEM_EXCEPTION(NO_IMPLEMENT);     // implementation unavailable
00323 TAO_SYSTEM_EXCEPTION(BAD_TYPECODE);     // bad typecode
00324 TAO_SYSTEM_EXCEPTION(BAD_OPERATION);    // invalid operation
00325 TAO_SYSTEM_EXCEPTION(NO_RESOURCES);     // out of resources for request
00326 TAO_SYSTEM_EXCEPTION(NO_RESPONSE);      // response not yet available
00327 TAO_SYSTEM_EXCEPTION(PERSIST_STORE);    // persistent storage failure
00328 TAO_SYSTEM_EXCEPTION(BAD_INV_ORDER);    // routine invocations out of order
00329 TAO_SYSTEM_EXCEPTION(TRANSIENT);        // transient error, try again later
00330 TAO_SYSTEM_EXCEPTION(FREE_MEM);         // cannot free memory
00331 TAO_SYSTEM_EXCEPTION(INV_IDENT);        // invalid identifier syntax
00332 TAO_SYSTEM_EXCEPTION(INV_FLAG);         // invalid flag was specified
00333 TAO_SYSTEM_EXCEPTION(INTF_REPOS);       // interface repository unavailable
00334 TAO_SYSTEM_EXCEPTION(BAD_CONTEXT);      // error processing context object
00335 TAO_SYSTEM_EXCEPTION(OBJ_ADAPTER);      // object adapter failure
00336 TAO_SYSTEM_EXCEPTION(DATA_CONVERSION);  // data conversion error
00337 TAO_SYSTEM_EXCEPTION(INV_POLICY);       // invalid policies present
00338 TAO_SYSTEM_EXCEPTION(REBIND);           // rebind needed
00339 TAO_SYSTEM_EXCEPTION(TIMEOUT);          // operation timed out
00340 TAO_SYSTEM_EXCEPTION(TRANSACTION_UNAVAILABLE); // no transaction
00341 TAO_SYSTEM_EXCEPTION(TRANSACTION_MODE);        // invalid transaction mode
00342 TAO_SYSTEM_EXCEPTION(TRANSACTION_REQUIRED);    // operation needs transaction
00343 TAO_SYSTEM_EXCEPTION(TRANSACTION_ROLLEDBACK);  // operation was a no-op
00344 TAO_SYSTEM_EXCEPTION(INVALID_TRANSACTION);     // invalid TP context passed
00345 TAO_SYSTEM_EXCEPTION(CODESET_INCOMPATIBLE);    // incompatible code set
00346 TAO_SYSTEM_EXCEPTION(BAD_QOS);          // bad quality of service
00347 TAO_SYSTEM_EXCEPTION(INVALID_ACTIVITY);
00348 TAO_SYSTEM_EXCEPTION(ACTIVITY_COMPLETED);
00349 TAO_SYSTEM_EXCEPTION(ACTIVITY_REQUIRED);
00350 
00351 #undef TAO_SYSTEM_EXCEPTION
00352 
00353 /**
00354  * @class TAO_Exceptions
00355  *
00356  * @brief This class is a namespace for exception-related static data and
00357  * methods.
00358  */
00359 class TAO_Export TAO_Exceptions
00360 {
00361 public:
00362   /**
00363    * Make the TypeCode for a standard exception.  When used correctly,
00364    * initializing system exceptions is only an exercise in CPU time;
00365    * it allocates no new memory.
00366    */
00367   static void make_standard_typecode (CORBA::TypeCode_ptr &tcp,
00368                                       const char *name,
00369                                       char *buf,
00370                                       size_t buflen
00371                                       ACE_ENV_ARG_DECL_WITH_DEFAULTS);
00372 
00373   /// Make the TypeCode for the CORBA::UnknownUserException standard
00374   /// exception.
00375   static void make_unknown_user_typecode (CORBA::TypeCode_ptr &tcp
00376                                           ACE_ENV_ARG_DECL_WITH_DEFAULTS);
00377 
00378   /// Runtime initialization of all standard exception typecodes.
00379   /// Called from <CORBA::ORB_init>.
00380   static void init (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
00381 
00382   /// Runtime finalization of all standard exception typecodes.
00383   static void fini (void);
00384 
00385   /// Create a CORBA::SystemException given the interface repository ID.
00386   static CORBA_SystemException *create_system_exception (
00387       const char *id
00388       ACE_ENV_ARG_DECL_WITH_DEFAULTS
00389     );
00390 
00391 
00392   /**
00393    * This global allocator is used to initialize system exception
00394    * typecodes.  Since at the time, the ORB is mostly still not
00395    * available.  Using a separate allocator prevents CDR routines from
00396    * accessing the optimized allocators from the ORB.
00397    */
00398   static ACE_Allocator *global_allocator_;
00399 
00400 private:
00401   /// Flag that denotes that the TAO's CORBA exceptions have been
00402   /// initialized.
00403   static int initialized_;
00404 };
00405 
00406 #if defined (TAO_DONT_CATCH_DOT_DOT_DOT)
00407 /**
00408  * @class TAO_DONT_CATCH
00409  *
00410  * @brief This class is only used internally in TAO as an exception
00411  * that never gets thrown.  Never use this class anywhere.
00412  */
00413 class TAO_Export TAO_DONT_CATCH
00414 {
00415 public:
00416   TAO_DONT_CATCH (void);
00417 };
00418 #endif /* TAO_DONT_CATCH_DOT_DOT_DOT */
00419 
00420 #if defined (__ACE_INLINE__)
00421 # include "tao/Exception.i"
00422 #endif /* __ACE_INLINE__ */
00423 
00424 #include "ace/post.h"
00425 #endif /* TAO_EXCEPTION_H */

Generated on Mon Jun 16 13:48:23 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002