feat(Exception)

This commit is contained in:
2024-09-30 16:17:24 +03:00
parent 7e78bca810
commit 4eaf5b53c0
5 changed files with 111 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include <basen/base58.hpp>
#include <basen/base64.hpp>
#include <basen/baseN.hpp>
#include <basen/Exception.hpp>
#include <basen/hash/sha256.hpp>
#include <basen/hex.hpp>

View File

@ -0,0 +1,44 @@
#pragma once
#include <cstdint>
#include <exception>
#include <source_location>
#include <string>
#include <unordered_map>
namespace basen
{
class Exception : public std::exception
{
public:
enum class Code
{
BASE,
PADDING,
CHECKSUM,
OVERFLOW,
LENGTH,
OUT_OF_ALPH,
ALPH_COLLISION
};
static const std::unordered_map<Code, std::string> messages;
Exception(Code code, const std::source_location &location = std::source_location::current());
const char *what() const noexcept override
{
return _what.c_str();
}
inline const char *message() const noexcept
{
return messages.at(_code).c_str();
}
inline Code code() const noexcept
{
return _code;
}
private:
Code _code;
std::string _what;
};
}