1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/inc/xna/exception.hpp
2024-06-27 20:42:55 -03:00

50 lines
1.7 KiB
C++

#ifndef XNA_EXCEPTION_HPP
#define XNA_EXCEPTION_HPP
#include <stdexcept>
#include <string>
#include <source_location>
namespace xna {
//A list of standard exceptions
struct ExMessage {
inline static const std::string InvalidOperation = "An invalid operation occurred.";
inline static const std::string InitializeComponent = "Unable to initialize component";
inline static const std::string CreateComponent = "Failed to create component";
inline static const std::string ApplyComponent = "Failed to apply component";
inline static const std::string UnintializedComponent = "Component is not initialized";
inline static const std::string MakeWindowAssociation = "Failed to create association with window";
inline static const std::string BuildObject = "Unable to build object";
inline static const std::string NotImplemented = "Not Implemented";
inline static const std::string ArgumentIsNull = "The argument is null or one of its values.";
};
//Structure for throwing exceptions with a message and information from the source file
struct Exception {
//Raises an exception with a message. Source file information is automatically captured.
static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) {
std::string error;
error.append("Exception in: ");
#if _DEBUG
error.append(location.file_name());
error.append("(");
error.append(std::to_string(location.line()));
error.append(":");
error.append(std::to_string(location.column()));
error.append(") ");
#endif
error.append("'");
error.append(location.function_name());
error.append("': ");
error.append(message);
error.append("\n");
throw std::runtime_error(error);
}
};
}
#endif