//
// PostgreSQLException.h
//
// $Id: //poco/1.5/Data/PostgreSQL/include/Poco/Data/PostgreSQL/PostgreSQLException.h#1 $
//
// Library: Data
// Package: PostgreSQL
// Module:  PostgreSQLException
//
// Definition of the PostgreSQLException class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
// 
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//


#ifndef Data_PostgreSQL_PostgreSQLException_INCLUDED
#define Data_PostgreSQL_PostgreSQLException_INCLUDED

#include "Poco/Data/PostgreSQL/PostgreSQL.h"
#include "Poco/Data/DataException.h"

#include <typeinfo>
#include <string>

namespace Poco {
namespace Data {
namespace PostgreSQL {

// End-user include this file and use in code ConnectionException/StatementException
// So it need not know 

class PostgreSQL_API PostgreSQLException: public Poco::Data::DataException
	/// Base class for all PostgreSQL exceptions
{
public:

	PostgreSQLException(const std::string& aMessage);
		/// Creates PostgreSQLException.

	PostgreSQLException(const PostgreSQLException& exc);
		/// Creates PostgreSQLException.

	~PostgreSQLException() throw();
		/// Destroys PostgreSQLexception.

	PostgreSQLException& operator=(const PostgreSQLException& exc);
		/// Assignment operator.

	const char* name() const throw();
		/// Returns exception name.

	const char* className() const throw();
		/// Returns the name of the exception class.

	Poco::Exception* clone() const;
		/// Creates an exact copy of the exception.
		///
		/// The copy can later be thrown again by
		/// invoking rethrow() on it.

	void rethrow() const;
		/// (Re)Throws the exception.
		///
		/// This is useful for temporarily storing a
		/// copy of an exception (see clone()), then
		/// throwing it again.
};


class ConnectionException : public PostgreSQLException
	/// ConnectionException
{
public:

	ConnectionException(const std::string& aMessage);
		/// Creates ConnectionException from string.

};


class TransactionException : public ConnectionException
	/// TrabsactionException
{
public:

	TransactionException(const std::string& aMessage);
		/// Creates TransactionException from string.
};


class StatementException : public PostgreSQLException
	/// StatementException
{
public:

	StatementException(const std::string& aMessage);
		/// Creates StatementException from string.
};


//
// inlines
//

inline PostgreSQLException& PostgreSQLException::operator=(const PostgreSQLException& exc)
{
	Poco::Data::DataException::operator=(exc);
	return *this;
}

inline const char* PostgreSQLException::name() const throw()
{
	return "PostgreSQL";
}

inline const char* PostgreSQLException::className() const throw()
{
	return typeid(*this).name();
}

inline Poco::Exception* PostgreSQLException::clone() const
{
	return new PostgreSQLException(*this);
}

inline void PostgreSQLException::rethrow() const
{
	throw *this;
}


} } } // namespace Poco::Data::PostgreSQL

#endif //Data_PostgreSQL_PostgreSQLException_INCLUDED
