-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.cpp
More file actions
47 lines (37 loc) · 988 Bytes
/
Copy pathexception.cpp
File metadata and controls
47 lines (37 loc) · 988 Bytes
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
#include "exception.hpp"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
namespace w32
{
error_t get_error_code()
{
return ::GetLastError();
}
std::string get_message( error_t err )
{
struct local_deleter
{
HGLOBAL memory;
local_deleter( HGLOBAL mem ) : memory( mem ) {}
~local_deleter() { if ( this->memory ) ::LocalFree( this->memory); }
};
char * p = NULL;
/* DWORD len = */::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPSTR>(&p), 0, NULL);
local_deleter deleter( p );
return p;
}
exception::exception( error_t err )
: error( err ), message( get_message( err ) )
{}
exception::exception( const char * msg, error_t err )
: error( err ), message( msg + std::string(" (") + get_message( err ) + std::string(" )") )
{}
const char * exception::what() const
{
return (this->message.c_str());
}
exception::~exception()
{
}
}