2024-06-27 15:46:41 -03:00
|
|
|
|
#ifndef XNA_EXCEPTION_HPP
|
2024-06-22 10:11:31 -03:00
|
|
|
|
#define XNA_EXCEPTION_HPP
|
|
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <source_location>
|
|
|
|
|
|
|
|
|
|
namespace xna {
|
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-07-06 12:20:54 -03:00
|
|
|
|
static void Throw(std::string const& message = "", const std::source_location location = std::source_location::current()) {
|
2024-06-22 10:11:31 -03:00
|
|
|
|
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);
|
|
|
|
|
}
|
2024-07-06 12:20:54 -03:00
|
|
|
|
|
|
|
|
|
inline static const std::string FAILED_TO_CREATE = "Failed to create component.";
|
|
|
|
|
inline static const std::string FAILED_TO_APPLY = "Failed to apply component.";
|
|
|
|
|
inline static const std::string FAILED_TO_MAKE_WINDOW_ASSOCIATION = "Failed to create association with window.";
|
|
|
|
|
inline static const std::string UNABLE_TO_INITIALIZE = "Unable to initialize component.";
|
|
|
|
|
inline static const std::string UNABLE_TO_BUILD_OBJECT = "Unable to build object.";
|
|
|
|
|
inline static const std::string NOT_IMPLEMENTED = "Not Implemented.";
|
|
|
|
|
inline static const std::string ARGUMENT_IS_NULL = "The argument is null or one of its values.";
|
|
|
|
|
inline static const std::string INVALID_OPERATION = "An invalid operation occurred.";
|
2024-06-22 10:11:31 -03:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|