-
Notifications
You must be signed in to change notification settings - Fork 2
/
Exception.h
93 lines (74 loc) · 1.69 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
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string>
#include <exception>
namespace EShellMenu
{
//
// Constants
//
const size_t ERROR_STRING_BUF_SIZE = 768;
//
// Basic Exception
// 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 Exception
{
protected:
mutable tstring m_Message;
protected:
Exception()
{
}
public:
Exception( const tchar_t *msgFormat, ... )
{
va_list msgArgs;
va_start( msgArgs, msgFormat );
SetMessage( msgFormat, msgArgs );
va_end( msgArgs );
}
//
// These accessors are thow that re-throw blocks can amend the exception message
//
tstring& Get()
{
return m_Message;
}
const tstring& Get() const
{
return m_Message;
}
void Set(const tstring& message)
{
m_Message = message;
}
//
// This allow operation with std::exception case statements
//
virtual const tchar_t* What() const
{
return m_Message.c_str();
}
protected:
void SetMessage( const tchar_t* msgFormat, ... )
{
va_list msgArgs;
va_start( msgArgs, msgFormat );
SetMessage( msgFormat, msgArgs );
va_end( msgArgs );
}
void SetMessage( const tchar_t* msgFormat, va_list msgArgs )
{
tchar_t msgBuffer[ERROR_STRING_BUF_SIZE];
_sntprintf( msgBuffer, sizeof(msgBuffer) / sizeof( char ), msgFormat, msgArgs );
msgBuffer[sizeof(msgBuffer) / sizeof(msgBuffer[0]) - 1] = 0;
m_Message = msgBuffer;
}
};
}