drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::orm::DrogonDbException Class Reference

Mixin base class to identify drogon-db-specific exception types. More...

#include <drogon/orm/Exception.h>

Inheritance diagram for drogon::orm::DrogonDbException:

Public Member Functions

virtual ~DrogonDbException () noexcept
 Support run-time polymorphism, and keep this class abstract.
virtual const std::exception & base () const noexcept
 Return std::exception base-class object.

Detailed Description

Mixin base class to identify drogon-db-specific exception types.

If you wish to catch all exception types specific to drogon db for some reason, catch this type. All of drogon db'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.

Member Function Documentation

◆ base()

virtual const std::exception & drogon::orm::DrogonDbException::base ( ) const
inlinevirtualnoexcept

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 DrogonDbException to a specific exception type is not likely to work since DrogonDbException is not (and could not safely be) derived from std::exception.

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

try
{
// ...
}
{
std::cerr << e.base().what() << std::endl;
const drogon::orm::SqlError *s=dynamic_cast<const
if (s) std::cerr << "Query was: " << s->query() << std::endl;
}
Mixin base class to identify drogon-db-specific exception types.
Definition Exception.h:51
virtual const std::exception & base() const noexcept
Return std::exception base-class object.
Definition Exception.h:83
Exception class for failed queries.
Definition Exception.h:134
DROGON_EXPORT const std::string & query() const noexcept
The query whose execution triggered the exception.

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