mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa FullMessage csharp/exception
This commit is contained in:
parent
d8ea8afef5
commit
54c08bf436
@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <source_location>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include "sr.hpp"
|
||||
|
||||
namespace csharp {
|
||||
@ -128,6 +129,8 @@ namespace csharp {
|
||||
static constexpr size_t HR_ERROR_FILE_INVALID = 0x800703EE;
|
||||
};
|
||||
|
||||
using OptinalString = std::optional<std::string>;
|
||||
|
||||
class Exception : public std::runtime_error {
|
||||
public:
|
||||
Exception(std::source_location const& source = std::source_location::current())
|
||||
@ -138,6 +141,24 @@ namespace csharp {
|
||||
: Source(source), message(message), innerException(innerException), std::runtime_error(message) {}
|
||||
|
||||
constexpr virtual std::string Message() const { return message; }
|
||||
|
||||
constexpr virtual std::string FullMessage() const {
|
||||
std::string msg;
|
||||
|
||||
msg.append(message);
|
||||
msg.append(" In: ");
|
||||
msg.append(Source.file_name());
|
||||
msg.append(" (");
|
||||
msg.append(std::to_string(Source.line()));
|
||||
msg.append(",");
|
||||
msg.append(std::to_string(Source.column()));
|
||||
msg.append("); ");
|
||||
msg.append(Source.function_name());
|
||||
|
||||
return msg;
|
||||
|
||||
}
|
||||
|
||||
const std::shared_ptr<Exception>& InnerException() const { return innerException; }
|
||||
|
||||
// Retrieves the lowest exception (inner most) for the given Exception.
|
||||
@ -184,7 +205,17 @@ namespace csharp {
|
||||
}
|
||||
|
||||
constexpr std::string Message() const override {
|
||||
return Exception::Message().append(" Parameter: " + paramName + ".");
|
||||
if(!paramName.empty())
|
||||
return Exception::Message().append(" Parameter: " + paramName + ".");
|
||||
|
||||
return Exception::Message();
|
||||
}
|
||||
|
||||
constexpr std::string FullMessage() const override {
|
||||
if(!paramName.empty())
|
||||
return Exception::FullMessage().append(" Parameter: " + paramName + ".");
|
||||
|
||||
return Exception::Message();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -85,8 +85,22 @@ namespace xna {
|
||||
BeginRun();
|
||||
return StartGameLoop();
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
MessageBox(nullptr, e.what(), "XN65", MB_OK);
|
||||
catch (std::exception& e) {
|
||||
auto ex = dynamic_cast<csharp::Exception*>(&e);
|
||||
|
||||
std::string message;
|
||||
|
||||
if (ex == nullptr) {
|
||||
message = e.what();
|
||||
} else {
|
||||
#if DEBUG || _DEBUG
|
||||
message = ex->FullMessage();
|
||||
#else
|
||||
message = ex->Message();
|
||||
#endif
|
||||
}
|
||||
|
||||
MessageBox(nullptr, message.c_str(), "XN65", MB_OK);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user