errors 0.6.3
Loading...
Searching...
No Matches
code_error.hpp
1#pragma once
2
3#include <cassert>
4#include <cstring>
5#include <string>
6
7#include "errors/impl/runtime_error.hpp"
8
9namespace errors
10{
11
12namespace impl
13{
14
23template <typename Code>
24class code_error : public runtime_error {
25 public:
37 code_error(const std::string &message, Code code,
39 : runtime_error(message, std::move(location))
40 , code(code)
41 {
42 this->message += " [code=" + std::to_string(code) + "]";
43 }
44
45 const char *what() const noexcept override
46 {
47 return this->message.c_str();
48 }
49
52 Code code;
53};
54
55static_assert(!std::is_abstract<code_error<unsigned int>>());
56}
57}
std::optional< source_location > location() const noexcept override
Get the source location of this error, if any.
Definition base_error.hpp:28
An error that has a code.
Definition code_error.hpp:24
code_error(const std::string &message, Code code, source_location location)
Constructor with message, code and source_location.
Definition code_error.hpp:37
const char * what() const noexcept override
Get error message.
Definition code_error.hpp:45
Code code
The error code.
Definition code_error.hpp:52
An error that has a message.
Definition runtime_error.hpp:18
std::string message
The error message.
Definition runtime_error.hpp:41
The source location.
Definition source_location.hpp:46