dtl


VariantException

Category: exceptions Component type: type

Description

VariantException is thrown by the variant classes in the DTL, usually when a variant cannot internally be converted from one type to another or when a variant object receives an object of a type it does not know how to handle. An exception of this type stores strings representing which method the exception was thrown in and a message describing what error occurred. The call to the constructor initializes these strings. The user can extract a stringified message with all of this information from the exception using the standard what() method.

Definition

Defined in the VariantException.h header file.

Example: Trivial case of throwing and catching a VariantException

class UnknownToVariant
{
};

void IWillThrow()
{
   variant_t v = UnknownToVariant(); // create a variant using a type that variant_t can't convert
   char *str = v; // unknown conversion will cause this statement to throw a VariantException
}


int main()
{
   try
   {
       // call our method which throws
       IWillThrow();
   }
   catch (RootException &ex)
   {
       // can also say: cout << ex << endl;
       // operator<<() for RootExceptions just streams out what()
       cout << ex.what() << endl;
   }
   return 0; // won't reach here ... exception thrown above
}

Model of

Standard C++ library exception.

Public base classes

RootException

Members

Member Where defined Description
VariantException(const string &meth, const string &err) VariantException Constructor which takes a specific method and error string.
virtual const char* what() const throw() RootException Overrides behavior in std::exception. Returns a C string describing the exception, including the method it was thrown in, the error message describing why it was thrown, and what type of exception was thrown. Subclasses do and may override what() based on their needs. See Note [1] in class RootException.
virtual const TCHAR* twhat() const throw() RootException Returns a pointer to a TCHAR describing the exception, including the method it was thrown in, the error message describing why it was thrown, and what type of exception was thrown. Subclasses do and may override twhat() based on their needs. See Note [1] in RootException. This is useful for returning unicode error messages. See Unicode documentation.
friend ostream &operator<<(ostream &o, const RootException &ex) RootException Note that this is a friend function, and not a member. Streams out ex.what() to o. As what() is virtual, the appropriate version of that method will be called for ex.
friend wostream &operator<<(wostream &o, const RootException &ex) RootException Note that this is a friend function, and not a member. Streams out ex.twhat() to o. As twhat() is virtual, the appropriate version of that method will be called for ex.

Notes

None.

See also

RootException.


[DTL Home]

Copyright © 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

This site written using the ORB. [The ORB]

1