libbasen v1.1.0
encoding/decoding from arbitrary base
Loading...
Searching...
No Matches
Exception.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <exception>
4#include <source_location>
5#include <string>
6#include <unordered_map>
7
8namespace basen
9{
10 class Exception : public std::exception
11 {
12 public:
13 enum class Code
14 {
15 BASE,
16 PADDING,
19 LENGTH,
22 };
23 static const std::unordered_map<Code, std::string> messages;
24
25 Exception(Code code, const std::source_location &location = std::source_location::current());
26 const char *what() const noexcept override
27 {
28 return _what.c_str();
29 }
30 inline const char *message() const noexcept
31 {
32 return messages.at(_code).c_str();
33 }
34 inline Code code() const noexcept
35 {
36 return _code;
37 }
38
39 private:
40 Code _code;
41 std::string _what;
42 };
43}
Definition Exception.hpp:11
Code
Definition Exception.hpp:14
const char * message() const noexcept
Definition Exception.hpp:30
Code code() const noexcept
Definition Exception.hpp:34
Exception(Code code, const std::source_location &location=std::source_location::current())
static const std::unordered_map< Code, std::string > messages
Definition Exception.hpp:23
const char * what() const noexcept override
Definition Exception.hpp:26
Definition Exception.hpp:9