//
// See the file LICENSE for redistribution information.
//
// Copyright (c) 2002-2003
//	Sleepycat Software.  All rights reserved.
//
// $Id: XmlException.hpp,v 1.25 2003/10/07 16:08:18 merrells Exp $
//

#ifndef __XMLEXCEPTION_HPP
#define	__XMLEXCEPTION_HPP

#include "XmlPortability.hpp"
#include <exception>
#include <string>

class DbException;

namespace DbXml
{

class DBXML_EXPORT XmlException : public std::exception
{
public:
	/// Error codes
	enum ExceptionCode
	{
	    INTERNAL_ERROR,  ///< An internal error occured.
	    CONTAINER_OPEN,  ///< The container is open.
	    CONTAINER_CLOSED,  ///< The container is closed.
	    CONTAINER_PASSED_WRONG_OBJECT,  ///< The container was passed an object from another container.
	    INDEXER_PARSER_ERROR,  ///< XML Indexer could not parse a document.
	    DATABASE_ERROR,  ///< Berkeley DB reported a database problem.
	    XPATH_PARSER_ERROR,  ///< The XPath parser was unable to parse the XPath expression.
	    DOM_PARSER_ERROR,  ///< The DOM parser was unable to parse an XML document.
	    XPATH_EVALUATION_ERROR,  ///< The XPath evaluator was unable to execute the XPath expression.
	    NO_VARIABLE_BINDING,  ///< An XPath expression referred to variable without a value.
	    LAZY_EVALUATION,  ///< XmlResults is lazily evaluated.
	    DOCUMENT_NOT_FOUND,  ///< The specified document could not be found in the container.
	    CONTAINER_EXISTS,  ///< The container already exists.
	    UNKNOWN_INDEX,  ///< The indexing strategy name is unknown.
	    INVALID_VALUE, ///< An invalid parameter was passed.
		VERSION_MISMATCH ///< The container version and the dbxml library version are not compatible.
	};
	XmlException(ExceptionCode err, const std::string &description, const char *file = 0, int line = 0);
	XmlException(ExceptionCode err, const char *description, const char *file = 0, int line = 0);
	explicit XmlException(const DbException &e, const char *file = 0, int line = 0);
	XmlException(int dberr, const char *file = 0, int line = 0);
	XmlException(const XmlException &);
	virtual ~XmlException() throw();
	virtual const char *what() const throw();
	/// Get the the error code for this exception.
	ExceptionCode getExceptionCode() const
	{
		return exceptionCode_;
	}
	/// Get the Berkeley DB errno for the DATABASE_ERROR.
	int getDbErrno() const
	{
		return dberr_;
	}

private:
	XmlException &operator = (const XmlException &);
	void describe();

	ExceptionCode exceptionCode_;
	int dberr_; // The Berkeley DB errno
	char *description_;
	const char *file_; // The file where the bad thing happened.
	int line_; // The line where the bad thing happened.
	char *text_;
};

}

#endif

