matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
Errors.hpp
Go to the documentation of this file.
1
6#ifndef MATF_RG_PROJECT_ERRORS_HPP
7#define MATF_RG_PROJECT_ERRORS_HPP
8
9#include <source_location>
10#include <string>
11#include <utility>
12#include <format>
13
14namespace engine::util {
22 class Error : public std::exception {
23 public:
29 explicit Error(std::string message, std::source_location location = std::source_location::current())
30 : m_message(std::move(message))
32 }
33
38 const std::string &message() const {
39 return m_message;
40 }
41
46 std::source_location location() const {
47 return m_location;
48 }
49
54 virtual std::string report() const {
55 return m_message;
56 };
57
58 private:
59 std::string m_message;
60 std::source_location m_location;
61 };
62
67 class EngineError final : public Error {
68 public:
110
116 static std::string_view type_string(Type error);
117
124 EngineError(Type error_type, std::string message,
125 std::source_location location = std::source_location::current())
126 : Error(std::move(message), std::move(location))
127 , m_error(error_type) {
128 }
129
134 std::string report() const override;
135
136 private:
138 };
139
152 class UserError : public Error {
153 public:
154 using Error::Error;
155 };
156} // namespace engine
157
164#define RG_GUARANTEE(expr, msg, ...) \
165 do { \
166 if (!(expr)) { \
167 throw engine::util::EngineError(engine::util::EngineError::Type::GuaranteeViolation, std::format(msg, ##__VA_ARGS__), std::source_location::current()); \
168 } \
169 } while (0)
170
176#define RG_SHOULD_NOT_REACH_HERE(msg, ...) \
177 do { \
178 throw engine::util::EngineError(engine::util::EngineError::Type::ShouldNotReachHere, std::format(msg, ##__VA_ARGS__), std::source_location::current()); \
179 } while (0)
180
186#define RG_UNIMPLEMENTED(msg, ...) \
187 do { \
188 throw engine::util::EngineError(engine::util::EngineError::Type::Unimplemented, std::format(msg, ##__VA_ARGS__), std::source_location::current()); \
189 } while (0)
190
197#define RG_ENGINE_ERROR(type, msg, ...) \
198 do { \
199 throw engine::util::EngineError(type, std::format(msg, ##__VA_ARGS__), std::source_location::current()); \
200 } while(0)
201
202#endif//MATF_RG_PROJECT_ERRORS_HPP
Represents an error that occurred in the engine.
Definition Errors.hpp:67
Type
The type of the engine error.
Definition Errors.hpp:72
@ ConfigurationError
The error that occurs when a configuration is invalid.
@ FileNotFound
The error that occurs when a file is not found.
@ ShouldNotReachHere
The error that occurs when a function should not reach a certain point. Use this to mark a path that ...
@ AssetLoadingError
The error that occurs when an asset loading fails.
@ OpenGLError
The error that occurs when an OpenGL error occurs.
@ ShaderCompilationError
The error that occurs when a shader compilation fails.
@ Unimplemented
The error that occurs when a function is not implemented. Use this during development to mark a funct...
@ GuaranteeViolation
The error that occurs when a guarantee is violated.
Type m_error
Definition Errors.hpp:137
EngineError(Type error_type, std::string message, std::source_location location=std::source_location::current())
Construct an EngineError.
Definition Errors.hpp:124
std::string report() const override
Get the error report.
Definition Errors.cpp:25
static std::string_view type_string(Type error)
Get the string representation of the engine error type.
Definition Errors.cpp:11
Base class for all errors.
Definition Errors.hpp:22
virtual std::string report() const
Get the error report. You can override this method in derived classes to provide a more detailed erro...
Definition Errors.hpp:54
const std::string & message() const
Get the error message.
Definition Errors.hpp:38
std::string m_message
Definition Errors.hpp:59
std::source_location location() const
Get the location of the error.
Definition Errors.hpp:46
Error(std::string message, std::source_location location=std::source_location::current())
Construct an Error.
Definition Errors.hpp:29
std::source_location m_location
Definition Errors.hpp:60
Represents an error that occurred in the user's code.
Definition Errors.hpp:152
Definition App.hpp:9