forked from HeliumProject/Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exception.h
120 lines (100 loc) · 2.82 KB
/
Exception.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma once
#include "Platform/Error.h"
#include "Platform/Console.h"
#include <vector>
#include <exception>
namespace Helium
{
//
// Constants
//
const size_t ERROR_STRING_BUF_SIZE = 768;
//
// Exception class
// Try to only throw in "error" cases. Examples:
// * A file format API trying to open a file that doesn't exist (the client api should check if it exists if it was graceful execution)
// * A disc drive or resource is out of space and cannot be written to
// * A network port is taken and cannot be bound
//
class HELIUM_PLATFORM_API Exception
{
protected:
Exception();
public:
Exception( const char *msgFormat, ... );
// These accessors are thow that re-throw blocks can amend the exception message
inline std::string& Get();
inline const std::string& Get() const;
inline void Set(const std::string& message);
// This allow operation with std::exception case statements
virtual const char* What() const;
protected:
void SetMessage( const char* msgFormat, ... );
void SetMessage( const char* msgFormat, va_list msgArgs );
mutable std::string m_Message;
};
namespace ExceptionTypes
{
enum ExceptionType
{
CPP,
#if HELIUM_OS_WIN
Structured,
#else
Signal
#endif
};
static const char* Strings[] =
{
TXT("C++"),
#if HELIUM_OS_WIN
TXT("Structured"),
#else
TXT("Signal"),
#endif
};
}
typedef ExceptionTypes::ExceptionType ExceptionType;
struct HELIUM_PLATFORM_API ExceptionArgs
{
ExceptionType m_Type;
bool m_Fatal;
std::string m_Message;
std::string m_Callstack;
std::vector< std::string > m_Threads;
std::string m_State;
// CPP-specific info
std::string m_CPPClass;
#if HELIUM_OS_WIN
// SEH-specific info
uint32_t m_SEHCode;
std::string m_SEHClass;
std::string m_SEHControlRegisters;
std::string m_SEHIntegerRegisters;
#endif
ExceptionArgs( ExceptionType type, bool fatal )
: m_Type( type )
, m_Fatal( fatal )
#if HELIUM_OS_WIN
, m_SEHCode( -1 )
#endif
{
};
};
/// @defgroup debugutility Debug Utility Functions
//@{
// Detects if a debugger is attached to the process
HELIUM_PLATFORM_API bool IsDebuggerPresent();
#if !HELIUM_RELEASE && !HELIUM_PROFILE
HELIUM_PLATFORM_API bool InitializeSymbols( const std::string& path = TXT("") );
HELIUM_PLATFORM_API bool GetSymbolsInitialized();
HELIUM_PLATFORM_API size_t GetStackTrace( void** ppStackTraceArray, size_t stackTraceArraySize, size_t skipCount = 1 );
HELIUM_PLATFORM_API void GetAddressSymbol( std::string& rSymbol, void* pAddress );
HELIUM_PLATFORM_API void DebugLog( const char* pMessage );
#endif
//@}
}
#ifdef HELIUM_OS_WIN
# include "Platform/ExceptionWin.h"
#endif
#include "Platform/Exception.inl"