libpqxx  4.0.1
pqxx::pqxx_exception Class Reference

Mixin base class to identify libpqxx-specific exception types. More...

#include <except.hxx>

Inheritance diagram for pqxx::pqxx_exception:
pqxx::argument_error pqxx::conversion_error pqxx::failure pqxx::internal_error pqxx::range_error pqxx::usage_error pqxx::broken_connection pqxx::in_doubt_error pqxx::sql_error pqxx::too_many_connections pqxx::data_exception pqxx::feature_not_supported pqxx::insufficient_privilege pqxx::insufficient_resources pqxx::integrity_constraint_violation pqxx::invalid_cursor_name pqxx::invalid_cursor_state pqxx::invalid_sql_statement_name pqxx::plpgsql_error pqxx::syntax_error

Public Member Functions

virtual ~pqxx_exception ()=0 throw ()
 Support run-time polymorphism, and keep this class abstract.
virtual const PQXX_CONST
std::exception & 
base () const =0 throw ()
 Return std::exception base-class object.

Detailed Description

Mixin base class to identify libpqxx-specific exception types.

If you wish to catch all exception types specific to libpqxx for some reason, catch this type. All of libpqxx's exception classes are derived from it through multiple-inheritance (they also fit into the standard library's exception hierarchy in more fitting places).

This class is not derived from std::exception, since that could easily lead to exception classes with multiple std::exception base-class objects. As Bart Samwel points out, "catch" is subject to some nasty fineprint in such cases.

Constructor & Destructor Documentation

pqxx::pqxx_exception::~pqxx_exception ( ) throw ()
pure virtual

Support run-time polymorphism, and keep this class abstract.

Member Function Documentation

virtual const PQXX_CONST std::exception& pqxx::pqxx_exception::base ( ) const throw ()
pure virtual

Return std::exception base-class object.

Use this to get at the exception's what() function, or to downcast to a more specific type using dynamic_cast.

Casting directly from pqxx_exception to a specific exception type is not likely to work since pqxx_exception is not (and could not safely be) derived from std::exception.

For example, to test dynamically whether an exception is an sql_error:

try
{
// ...
}
catch (const pqxx::pqxx_exception &e)
{
std::cerr << e.base().what() << std::endl;
const pqxx::sql_error *s=dynamic_cast<const pqxx::sql_error*>(&e.base());
if (s) std::cerr << "Query was: " << s->query() << std::endl;
}

The documentation for this class was generated from the following files: