SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Exception.h
1#pragma once
2
3#include <format>
4#include <source_location>
5#include <stdexcept>
6
7SPARK_WARNING_PUSH
8SPARK_DISABLE_MSVC_WARNING(4275) // non dll-interface class used as base for dll-interface class -> disabled since class is an stl class
9
10namespace spark::base::details
11{
15 class SPARK_BASE_EXPORT Exception : public std::runtime_error
16 {
17 public:
18 explicit Exception(const char* class_name, const std::string_view& message, const std::source_location& source_location)
19 : std::runtime_error(FormatMessage(class_name, message, source_location).c_str()) {}
20
21 ~Exception() override = default;
22
23 Exception(const Exception& other) = default;
24 Exception(Exception&& other) noexcept = default;
25 Exception& operator=(const Exception& other) = default;
26 Exception& operator=(Exception&& other) noexcept = default;
27
28 protected:
29 static std::string FormatMessage(const char* class_name, const std::string_view& message, const std::source_location& source_location)
30 {
31 return std::format("Exception of type {0} has been thrown.\nError happen in {1}:{2}.\nException contains the message:\n{3}",
32 class_name,
33 source_location.file_name(),
34 source_location.line(),
35 message);
36 }
37 };
38}
39
40SPARK_WARNING_POP
The base class for all exceptions in Spark. Should be used as a base class only.
Definition Exception.h:16