4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_Foundation_Common_Platform_Windows
9#error "WINDOWS REQUIRED FOR THIS MODULE"
14#include "Stroika/Foundation/Common/Common.h"
16#include "Stroika/Foundation/Containers/Common.h"
18#include "Stroika/Foundation/Execution/Exceptions.h"
21#include "StructuredException.h"
25using namespace Stroika::Foundation::Debug;
27using namespace Stroika::Foundation::Execution::Platform;
31 class StructuredException_error_category_ :
public error_category {
33 virtual const char* name () const noexcept
override
35 return "Windows Structured Exception error";
37 virtual error_condition default_error_condition ([[maybe_unused]]
int ev)
const noexcept override
42 return error_condition{errc::bad_message};
44 virtual string message (
int u)
const override
47 case EXCEPTION_ACCESS_VIOLATION:
48 return "EXCEPTION_ACCESS_VIOLATION";
49 case EXCEPTION_DATATYPE_MISALIGNMENT:
50 return "EXCEPTION_DATATYPE_MISALIGNMENT";
51 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
52 return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
53 case EXCEPTION_FLT_DENORMAL_OPERAND:
54 return "EXCEPTION_FLT_DENORMAL_OPERAND";
55 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
56 return "EXCEPTION_FLT_DENORMAL_OPERAND";
57 case EXCEPTION_FLT_INEXACT_RESULT:
58 return "EXCEPTION_FLT_INEXACT_RESULT";
59 case EXCEPTION_FLT_INVALID_OPERATION:
60 return "EXCEPTION_FLT_INVALID_OPERATION";
61 case EXCEPTION_FLT_OVERFLOW:
62 return "EXCEPTION_FLT_OVERFLOW";
63 case EXCEPTION_FLT_STACK_CHECK:
64 return "EXCEPTION_FLT_STACK_CHECK";
65 case EXCEPTION_FLT_UNDERFLOW:
66 return "EXCEPTION_FLT_UNDERFLOW";
67 case EXCEPTION_INT_DIVIDE_BY_ZERO:
68 return "EXCEPTION_INT_DIVIDE_BY_ZERO";
69 case EXCEPTION_INT_OVERFLOW:
70 return "EXCEPTION_INT_OVERFLOW";
71 case EXCEPTION_PRIV_INSTRUCTION:
72 return "EXCEPTION_PRIV_INSTRUCTION";
73 case EXCEPTION_IN_PAGE_ERROR:
74 return "EXCEPTION_IN_PAGE_ERROR";
75 case EXCEPTION_ILLEGAL_INSTRUCTION:
76 return "EXCEPTION_ILLEGAL_INSTRUCTION";
77 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
78 return "EXCEPTION_NONCONTINUABLE_EXCEPTION";
79 case EXCEPTION_STACK_OVERFLOW:
80 return "EXCEPTION_STACK_OVERFLOW";
81 case EXCEPTION_INVALID_DISPOSITION:
82 return "EXCEPTION_INVALID_DISPOSITION";
83 case EXCEPTION_GUARD_PAGE:
84 return "EXCEPTION_GUARD_PAGE";
85 case EXCEPTION_INVALID_HANDLE:
86 return "EXCEPTION_INVALID_HANDLE";
89 (void)::snprintf (buf, Memory::NEltsOf (buf),
"#0x%x", u);
104 return Common::Immortalize<StructuredException_error_category_> ();
108 void trans_func_ (
unsigned int u, EXCEPTION_POINTERS* pExp)
112 using namespace Characters::Literals;
115 if (pExp !=
nullptr) {
116 if (pExp->ContextRecord !=
nullptr) {
118 DbgTrace (
"ContextRecord->ContextFlags = 0x{:x}"_f, pExp->ContextRecord->ContextFlags);
119 DbgTrace (
"ContextRecord->Dr0 = 0x{:x}"_f, pExp->ContextRecord->Dr0);
120#if qStroika_Foundation_Common_Platform_Win32
121 DbgTrace (
"ContextRecord->Esp = 0x{:x}"_f, pExp->ContextRecord->Esp);
124 if (pExp->ExceptionRecord !=
nullptr) {
126 DbgTrace (
"ExceptionRecord->ExceptionAddress = 0x{:x}"_f, pExp->ExceptionRecord->ExceptionAddress);
127 DbgTrace (
"ExceptionRecord->ExceptionCode = 0x{:x}"_f, pExp->ExceptionRecord->ExceptionCode);
128 DbgTrace (
"ExceptionRecord->ExceptionFlags = 0x{:x}"_f, pExp->ExceptionRecord->ExceptionFlags);
129 DbgTrace (
"ExceptionRecord->NumberParameters = {}"_f, pExp->ExceptionRecord->NumberParameters);
133 DbgTrace (
"Translating it into a Platform::Windows::StructuredException::THROW()"_f);
147 _set_se_translator (trans_func_);
148 DISABLE_COMPILER_MSC_WARNING_END (4535)
DISABLE_COMPILER_MSC_WARNING_START(4996)
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...