13.1.11 Exceptions

An exception in OMG IDL is mapped to a C++ class. The C++ class contains the following:

  • Constructors
  • Destructors
  • A static_narrow function, to determine the type of exception

The generated class is similar to a variable-length structure, but with an additional constructor to simplify initialization, and with the static _narrow member function to determine the type of UserException.

For example, consider the following OMG IDL definition:

// OMG IDL
module INVENT
    {
    exception NonExist
        {
        ID BadId;
        };
};

This definition maps to C++ as follows:

// C++
class INVENT
    {
    . . .
    class NonExist : public CORBA::UserException
        {
        public:
            static NonExist * _narrow(CORBA::Exception_ptr);
            NonExist (ID _BadId);
            NonExist ();
            NonExist (const NonExist &);
            ~NonExist ();
            NonExist & operator=(const NonExist &);
            void _raise ();
            ID BadId;
         };
};

Attributes (data members) of the Exception class are public, so you may access them directly.