Class DrogonDbException


#include <orm_lib/inc/drogon/orm/Exception.h>

class DROGON_EXPORT DrogonDbException


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.

Mentioned in


Decsendents: RangeError, ConversionError, ArgumentError, UsageError, Failure, TimeoutError, InternalError


~DrogonDbExceptionSupport run-time polymorphism, and keep this class abstract.
baseReturn std::exception base-class object.


Lines 50-88 in orm_lib/inc/drogon/orm/Exception.h.

class DROGON_EXPORT DrogonDbException
    /// Support run-time polymorphism, and keep this class abstract
    virtual ~DrogonDbException() noexcept

    /// 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:
     * @code
     * try
     * {
     *   // ...
     * }
     * catch (const drogon::orm::DrogonDbException &e)
     * {
     *   std::cerr << e.base().what() << std::endl;
     *   const drogon::orm::SqlError *s=dynamic_cast<const
     * drogon::orm::SqlError*>(&e.base());
     *   if (s) std::cerr << "Query was: " << s->query() << std::endl;
     * }
     * @endcode
    virtual const std::exception &base() const noexcept
        static std::exception except;
        return except;
    }  //[t00]

Add Discussion as Guest

Log in