2024-06-22 10:11:31 -03:00
|
|
|
#ifndef XNA_EXCEPTION_HPP
|
|
|
|
#define XNA_EXCEPTION_HPP
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
#include <source_location>
|
|
|
|
|
|
|
|
namespace xna {
|
2024-06-22 11:52:21 -03:00
|
|
|
|
|
|
|
//A list of standard exceptions
|
2024-06-22 10:11:31 -03:00
|
|
|
struct ExMessage {
|
2024-06-22 11:02:01 -03:00
|
|
|
inline static const std::string InvalidOperation = "An invalid operation occurred.";
|
2024-06-22 10:11:31 -03:00
|
|
|
inline static const std::string InitializeComponent = "Unable to initialize component";
|
2024-06-22 11:02:01 -03:00
|
|
|
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";
|
2024-06-22 11:52:21 -03:00
|
|
|
inline static const std::string BuildObject = "Unable to build object";
|
2024-06-25 15:41:11 -03:00
|
|
|
inline static const std::string NotImplemented = "Not Implemented";
|
2024-06-22 10:11:31 -03:00
|
|
|
};
|
|
|
|
|
2024-06-22 11:52:21 -03:00
|
|
|
//Structure for throwing exceptions with a message and information from the source file
|
2024-06-22 10:11:31 -03:00
|
|
|
struct Exception {
|
2024-06-22 11:52:21 -03:00
|
|
|
|
|
|
|
//Raises an exception with a message. Source file information is automatically captured.
|
2024-06-22 10:11:31 -03:00
|
|
|
static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) {
|
|
|
|
std::string error;
|
|
|
|
|
2024-06-22 11:02:01 -03:00
|
|
|
error.append("Exception in: ");
|
2024-06-22 10:11:31 -03:00
|
|
|
#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
|