Function base


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

virtual const std::exception & base() const 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:

  // ...
catch (const drogon::orm::DrogonDbException &e)
  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;


Lines 80-84 in orm_lib/inc/drogon/orm/Exception.h.

virtual const std::exception &base() const noexcept
    static std::exception except;
    return except;
}  //[t00]

Add Discussion as Guest

Log in