3#include "elementa/license.inc"
4#include "elementa/checks.inc"
6#ifndef ELEMENTA_BASE_EXCEPTIONS_H
7#define ELEMENTA_BASE_EXCEPTIONS_H
64#define ELE_CLASS_EXCOVERRIDE(C) C & asERR(const std::string & contxt) noexcept\
66 { elementa::base::Exc::asERR(contxt); \
68 C & asEXC(const std::string & place, \
69 const elementa::base::RTTextWithEnum::\
71 {elementa::base::RTTextWith::kAll_}) \
73 { elementa::base::Exc::asEXC(place,fl); \
112class Exc:
public std::runtime_error
119 using StdBase = std::runtime_error;
128 Exc(
const std::string & expl):StdBase{expl},iserr_{false} {}
130 Exc(
const Exc &) =
default;
132 Exc & operator=(
const Exc &) =
default;
133 Exc & operator=(
Exc &&) =
default;
135 virtual ~Exc(
void) =
default;
149 const RTTextWithEnum::Combination & flags =
150 {RTTextWith::kAll_})
noexcept;
161 const char *
what(
void)
const noexcept override {
return(msg_.c_str()); }
164 const char *
explanation(
void)
const noexcept {
return(StdBase::what()); }
167 const char *
context(
void)
const noexcept {
return(context_.c_str()); }
178 std::string context_;
263 invarg(
const std::string & expl):
Exc{expl} {}
289#define ELE_CODE_UNIMPLEMENTED throw(elementa::base::unimplemented{\
290 "Unimplemented"}.asEXC(ELE_CODE_PLACE))
293#define ELE_CODE_TODO(expl) throw(elementa::base::todo{expl}.asEXC(\
297#define ELE_CODE_NOTREACH throw(elementa::base::notreach{\
298 "Should not reach this point"}.asEXC(\
302#define ELE_CODE_INTERNALERR(expl) throw(elementa::base::internal_error{expl}.\
303 asEXC(ELE_CODE_PLACE))
306#define ELE_CODE_INVSTATE(expl) throw(elementa::base::invstate{expl}.\
307 asEXC(ELE_CODE_PLACE))
310#define ELE_CODE_INVARG(expl) throw(elementa::base::invarg{expl}.\
311 asEXC(ELE_CODE_PLACE))
314#define ELE_CODE_OUTOFRANGE(expl) throw(elementa::base::outofrange{expl}.\
315 asEXC(ELE_CODE_PLACE))
318#define ELE_CODE_NOTFOUND(expl) throw(elementa::base::notfound{expl}.\
319 asEXC(ELE_CODE_PLACE))
Exc(const std::string &expl)
Constructor from an explanation. To be thrown as EXC by default.
const char * context(void) const noexcept
Return the place (EXC) or context (ERR) only. Will live as long as this.
virtual Exc & asEXC(const std::string &place, const RTTextWithEnum::Combination &flags={RTTextWith::kAll_}) noexcept
Transform it to be thrown as EXC with the given place and flags.
const char * what(void) const noexcept override
Return the complete message. It will live as long as this exception.
const char * explanation(void) const noexcept
Return the explanation only. It will live as long as this exception.
virtual Exc & asERR(const std::string &context) noexcept
Transform it to be thrown as ERR with the given context.
Base class for all errors / exceptions in Elementa. Just derive from it.
Exception for indicating some internal error not caused by user of object.
Exception for indicating that some argument of a method/function is invalid.
Exception for indicating that some object is in invalid state.
Exception for indicating that some element has not been found in some place.
Exception for indicating in runtime that a code should not be reached.
Exception for indicating that some value is out of range.
Exception for indicating in runtime that a section of code is TODO.
Exception for indicating in runtime that a section of code is unimplemented.
#define ELE_CLASS_EXCOVERRIDE(C)
Shortening macro that must be used inside classes derived from Exc.