MDLParser
Simple and modern library for parsing the Source engine model formats
Loading...
Searching...
No Matches
errors.hpp
1#pragma once
2
3#include <cstdint>
4#include <stdexcept>
5
6#define ERROR_FOR_REASON(reason) \
7 class reason : public Error { \
8 public: \
9 explicit reason(const char* message) : Error(Reason::reason, message) {} \
10 };
11
12namespace MdlParser::Errors {
13 enum class Reason : uint8_t {
14 InvalidHeader,
15 InvalidBody,
16 InvalidChecksum,
17 UnsupportedVersion,
18 OutOfBoundsAccess,
19 };
20
21 class Error : public std::runtime_error {
22 public:
23 Error(Reason reason, const char* message) : reason(reason), std::runtime_error(message) {}
24
25 Reason getReason() {
26 return reason;
27 }
28
29 private:
30 Reason reason;
31 };
32
33 ERROR_FOR_REASON(InvalidHeader);
34 ERROR_FOR_REASON(InvalidBody);
35 ERROR_FOR_REASON(InvalidChecksum);
36 ERROR_FOR_REASON(UnsupportedVersion);
37 ERROR_FOR_REASON(OutOfBoundsAccess);
38}
Definition: errors.hpp:21