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