720d6bbcd8
c24f918e5 oaknut: 1.1.6 3a70cd40a oaknut: Run clang-format dc54784b8 oaknut: Add support for iOS memory protection. 14207278a oaknut: 1.1.5 841f9b693 oaknut: throw OaknutException instead of plain C string git-subtree-dir: externals/oaknut git-subtree-split: c24f918e52e629fc315c6e4bca4ea62def8b55e8
44 lines
883 B
C++
44 lines
883 B
C++
// SPDX-FileCopyrightText: Copyright (c) 2023 merryhime <https://mary.rs>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <exception>
|
|
|
|
namespace oaknut {
|
|
|
|
enum class ExceptionType {
|
|
#define OAKNUT_EXCEPTION(tag, str) tag,
|
|
#include "oaknut/impl/oaknut_exception.inc.hpp"
|
|
#undef OAKNUT_EXCEPTION
|
|
};
|
|
|
|
inline const char* to_string(ExceptionType et)
|
|
{
|
|
switch (et) {
|
|
#define OAKNUT_EXCEPTION(tag, str) \
|
|
case ExceptionType::tag: \
|
|
return str;
|
|
#include "oaknut/impl/oaknut_exception.inc.hpp"
|
|
#undef OAKNUT_EXCEPTION
|
|
default:
|
|
return "unknown ExceptionType";
|
|
}
|
|
}
|
|
|
|
class OaknutException : public std::exception {
|
|
public:
|
|
explicit OaknutException(ExceptionType et)
|
|
: type{et}
|
|
{}
|
|
|
|
const char* what() const noexcept override
|
|
{
|
|
return to_string(type);
|
|
}
|
|
|
|
private:
|
|
ExceptionType type;
|
|
};
|
|
|
|
} // namespace oaknut
|