arabica/include/DOM/DOMException.hpp

136 lines
2.9 KiB
C++
Raw Permalink Normal View History

2002-06-21 13:16:28 +02:00
#ifndef JEZUK_DOM_EXCEPTION_H
#define JEZUK_DOM_EXCEPTION_H
////////////////////////////
// C++ DOM definition
////////////////////////////
#include <stdexcept>
#include <typeinfo>
2002-06-21 13:16:28 +02:00
2007-09-05 13:47:13 +02:00
namespace Arabica
{
2002-06-21 13:16:28 +02:00
namespace DOM
{
2010-12-10 10:24:34 +01:00
class DOMBadCast : public std::bad_cast
{
public:
DOMBadCast(const char* expectedType) :
message_(std::string("Cannot cast to ") + expectedType)
{
} // DOMBadCast
DOMBadCast(const DOMBadCast& rhs) :
message_(rhs.message_)
{
} // DOMBadCase
virtual ~DOMBadCast() throw()
{
} // DOMBadCast
2010-12-10 10:24:34 +01:00
virtual const char* what() const throw()
{
return message_.c_str();
} // what
private:
const std::string message_;
DOMBadCast& operator=(const DOMBadCast&);
bool operator==(const DOMBadCast&) const;
}; // DOMBadCast
2002-06-21 13:16:28 +02:00
class DOMException : public std::runtime_error
{
public:
enum CODE
{
2010-12-11 02:10:21 +01:00
INDEX_SIZE_ERR = 1,
DOMSTRING_SIZE_ERR = 2,
HIERARCHY_REQUEST_ERR = 3,
WRONG_DOCUMENT_ERR = 4,
INVALID_CHARACTER_ERR = 5,
NO_DATA_ALLOWED_ERR = 6,
NO_MODIFICATION_ALLOWED_ERR = 7,
NOT_FOUND_ERR = 8,
NOT_SUPPORTED_ERR = 9 ,
INUSE_ATTRIBUTE_ERR = 10,
2002-06-21 13:16:28 +02:00
INVALID_STATE_ERR,
SYNTAX_ERR,
INVALID_MODIFICATION_ERR,
NAMESPACE_ERR,
INVALID_ACCESS_ERR
}; // enum CODE
2010-12-10 10:24:34 +01:00
DOMException(CODE code) :
std::runtime_error("DOMException"),
code_(code)
{
} // DOMException
DOMException(const DOMException& rhs) :
std::runtime_error(rhs),
code_(rhs.code_)
{
} // DOMException
2003-10-29 17:10:31 +01:00
virtual ~DOMException() throw()
{
} // DOMBadCast
2003-10-29 17:10:31 +01:00
CODE code() const { return code_; }
virtual const char* what() const throw()
{
switch(code_)
{
case INDEX_SIZE_ERR:
return "Index size error";
case DOMSTRING_SIZE_ERR:
return "DOMString size error";
case HIERARCHY_REQUEST_ERR:
return "Hierarchy request error";
case WRONG_DOCUMENT_ERR:
return "Wrong Document error";
case INVALID_CHARACTER_ERR:
return "Invalid Character error";
case NO_DATA_ALLOWED_ERR:
return "No data allowed error";
case NO_MODIFICATION_ALLOWED_ERR:
return "No modification allowed error";
case NOT_FOUND_ERR:
return "Not found error";
case NOT_SUPPORTED_ERR:
return "Not supported error";
case INUSE_ATTRIBUTE_ERR:
return "Attribute inuse error";
case INVALID_STATE_ERR:
return "Invalid state";
case SYNTAX_ERR:
return "Syntax error";
case INVALID_MODIFICATION_ERR:
return "Invalid modification error";
case NAMESPACE_ERR:
return "Namespace error";
case INVALID_ACCESS_ERR:
return "Invalid access error";
} // switch(code_)
return "DOM error";
} // what
private:
2010-12-10 10:24:34 +01:00
DOMBadCast& operator=(const DOMBadCast&);
bool operator==(const DOMBadCast&) const;
2003-10-29 17:10:31 +01:00
CODE code_;
}; // class DOMException
2002-06-21 13:16:28 +02:00
} // namespace DOM
2007-09-05 13:47:13 +02:00
} // namespace Arabica
2002-06-21 13:16:28 +02:00
#endif