-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStdException.h
67 lines (57 loc) · 1.98 KB
/
StdException.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//////////////////////////////////////////////////////////////////////////
//
// StdException. Catches Safe Exceptions and normal exceptions alike
//
// Code based on original idea of "Martin Ziacek" on www.codeproject.com
// Exception class is now **NOT** based on any base class
//
//////////////////////////////////////////////////////////////////////////
#pragma once
#include <eh.h>
// Macro to re-throw a safe exception
#define ReThrowSafeException(ex) if(ex.GetSafeExceptionCode()) throw ex;
class StdException
{
public:
// Application type constructors
StdException(int p_errorCode);
StdException(LPCTSTR p_fault);
StdException(const CString& p_fault);
StdException(int p_errorCode,const char* p_fault);
// Construct from a SafeExceptionHandler (SEH)
StdException(UINT p_safe,_EXCEPTION_POINTERS* p_exceptionPointers);
StdException(const StdException& p_other);
UINT GetSafeExceptionCode();
_EXCEPTION_POINTERS* GetExceptionPointers();
PVOID GetExceptionAddress();
int GetApplicationCode();
CString GetApplicationFault();
CString GetErrorMessage();
BOOL GetErrorMessage(LPCTSTR p_error,UINT p_maxSize,PUINT p_helpContext = NULL);
private:
UINT m_safeExceptionCode { 0 };
_EXCEPTION_POINTERS* m_exceptionPointers { nullptr };
UINT m_applicationCode { 0 };
CString m_applicationFault;
};
void SeTranslator(UINT p_safe,_EXCEPTION_POINTERS* p_exceptionPointers);
#ifndef MARLIN_USE_ATL_ONLY
// Translate CException to CString
CString MessageFromException(CException& p_exception);
#endif
// Auto class to store the SE translator function
// Of an original source system, while setting our own
class AutoSeTranslator
{
public:
AutoSeTranslator(_se_translator_function p_func)
{
m_original = _set_se_translator(p_func);
}
~AutoSeTranslator()
{
_set_se_translator(m_original);
}
private:
_se_translator_function m_original;
};