This chapter describes the following classes:
wcexcept.h
The WCExcept class provides the exception handling for the container classes. If you've compiled your code with exception handling enabled, the C++ exception processing can be used to catch errors.
Your source file must be compiled with the exception-handling compile switch for C++ exception processing to occur; see the section ``C++ Exception Handling'' in the C/C++ Compiler Options chapter of the Watcom Compiler & Tools User's Guide. |
The container classes attempt to set the container object into a reasonable state if there is an error and exception handling isn't enabled, or if the trap for the specific error hasn't been enabled by your program.
By default, no exception traps are enabled, and no exceptions are thrown. Exception traps are enabled by setting the exception state with the exceptions() member function.
The wcexcept.h header file is included by the header files for each of the container classes. There's normally no need to include the wcexcept.h header file explicitly, but no errors result if you do. This class is inherited as a base class for each of the containers. You don't need to derive from it directly.
The WCListExcept class (formerly used by the list container classes) has been replaced by the WCExcept class. The WCListExcept class has been redefined to be the WCExcept class, and the wclist_state type to be the wc_state type, to provide backward compatability with previous versions of the list containers.
The following enumeration type definitions are declared in the public interface:
typedef int wc_state;
The following public member functions are declared:
WCExcept(); virtual ~WCExcept(); wc_state exceptions() const; wc_state exceptions( wc_state );
create a WCExcept object
#include <wcexcept.h> public: WCExcept();
The public WCExcept constructor creates a WCExcept object.
This constructor is used implicitly by the compiler when it generates a constructor for a derived class. It's automatically used by the list container classes, and shouldn't be required in any user-derived classes.
The public WCExcept constructor produces an initialized WCExcept object with no exception traps enabled.
destroy a WCExcept object
#include <wcexcept.h> public: virtual ~WCExcept();
The public WCExcept destructor doesn't do anything explicit. The call to it is inserted implicitly by the compiler at the point where the object derived from WCExcept goes out of scope.
The object derived from WCExcept is destroyed.
query and/or set the bits that enable exceptions for container classes
#include <wcexcept.h> public: wc_state exceptions() const; wc_state exceptions( wc_state set_flags );
The exceptions() public member function queries and/or sets the bits that control which exceptions are enabled for the container classes. Each bit corresponds to an exception, and is set if the exception is enabled.
The first form of this function returns the current settings of the exception bits; the second form sets the exception bits to those specified by set_flags.
The first form returns the current set of exception bits; the second form returns the old set.
a set of bits that represents the current state of the container object
#include <wcexcept.h> public: enum wcstate { all_fine = 0x0000, // no errors check_none = all_fine,// throw no exceptions not_empty = 0x0001, // container not empty index_range = 0x0002, // index is out of // range empty_container= 0x0004, // empty container // error out_of_memory = 0x0008, // allocation failed resize_required= 0x0010, // request needs resize not_unique = 0x0020, // adding duplicate zero_buckets = 0x0040, // resizing hash to // zero // value to use to check for all errors check_all = (not_empty|index_range |empty_container|out_of_memory |resize_required|not_unique |zero_buckets) }; typedef int wc_state;
The type WCExcept::wcstate is a set of bits representing the current state of the container object. The WCExcept::wc_state member type definition represents the same set of bits, but uses an int to represent the values, thereby avoiding problems made possible by the compiler's ability to use smaller types for enumerations.
You should use WCExcept::wc_state, not WCExcept::wcstate. |
The bit values defined by the WCExcept::wc_state member type definition can be read and set by the exceptions() member function, which is also used to control exception handling. The bit values are as follows:
wcexcept.h
The WCIterExcept class provides the exception handling for the container iterators. If you've compiled your code with exception handling enabled, the C++ exception processing can be used to catch errors.
Your source file must be compiled with the exception handling compile switch for C++ exception processing to occur; see the section ``C++ Exception Handling'' in the C/C++ Compiler Options chapter of the Watcom Compiler & Tools User's Guide. |
The iterators attempt to set the class into a reasonable state if there is an error and exception handling isn't enabled, or if the trap for the specific error hasn't been enabled by your program.
By default, no exception traps are enabled, and no exceptions are thrown. Exception traps are enabled by setting the exception state with the exceptions() member function.
The wcexcept.h header file is included by the header files for each of the iterator classes. There's normally no need to include the wcexcept.h header file explicitly, but no errors result if you do. This class is inherited as part of the base construction for each of the iterators. You don't need to derive from it directly.
The following enumeration typedefs are declared in the public interface:
typedef int wciter_state;
The following public member functions are declared:
WCIterExcept(); virtual ~WCIterExcept(); wciter_state exceptions() const; wciter_state exceptions( wciter_state );
create a WCIterExcept object
#include <wcexcept.h> public: WCIterExcept();
The public WCIterExcept constructor creates a WCIterExcept object.
This constructor is used implicitly by the compiler when it generates a constructor for a derived class.
This constructor produces an initialized WCIterExcept object with no exception traps enabled.
destroy a WCIterExcept object
#include <wcexcept.h> public: virtual ~WCIterExcept();
The public WCIterExcept destructor doesn't do anything explicit. The call to it is inserted implicitly by the compiler at the point where the object derived from WCIterExcept goes out of scope.
The object derived from WCIterExcept is destroyed.
query and/or set bits that enable exceptions for the iterator classes
#include <wcexcept.h> public: wciter_state exceptions() const; wciter_state exceptions( wciter_state set_flags );
The exceptions() public member function queries and/or sets the bits that control which exceptions are enabled for the iterator class. Each bit corresponds to an exception, and is set if the exception is enabled.
The first form of the function returns the current settings of the exception bits; the second form sets the exception bits to those specified by set_flags.
The first form returns the current set of exception bits; the second form returns the new set.
a set of bits that represent the current state of the iterator
#include <wcexcept.h> public: enum wciterstate { all_fine = 0x0000, // no errors check_none = all_fine,// disable all exceptions undef_iter = 0x0001, // position is undefined undef_item = 0x0002, // iterator item is // undefined iter_range = 0x0004, // advance value is bad // value to use to check for all errors check_all = (undef_iter|undef_item|iter_range) }; typedef int wciter_state;
The type WCIterExcept::wciterstate is a set of bits representing the current state of the iterator. The WCIterExcept::wciter_state member type definition represents the same set of bits, but uses an int to represent the values, thereby avoiding problems made possible by the compiler's ability to use smaller types for enumerations.
You should use WCIterExcept::wciter_state, not WCIterExcept::wciterstate. |
The bit values defined by the WCIterExcept::wciter_state member type definition can be read and set by the member function exceptions(), which is used to control exception handling. The bit values are as follows: