Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
windows_exception.cpp
Go to the documentation of this file.
1 /**
2  \file
3  \brief Contains WindowsException methods.
4 */
5 
6 
7 
8 
9 #include "windows_exception.h"
10 #include "helpers.h"
11 
12 #include <comdef.h> // _com_error
13 
14 #include <sstream>
15 
16 
17 
18 
19 /*==============================================================================
20  WindowsException methods
21 ==============================================================================*/
22 
23 
24 WindowsException::WindowsException( char const* const file, unsigned int const line, std::string const& what, HRESULT const hResult ) {
25 
26  _com_error error( hResult );
27 
28 #ifdef _UNICODE
29  wchar_t const* const message16 = error.ErrorMessage();
30  char message[ 256 ];
31  WideCharToMultiByte( CP_UTF8, 0, message16, -1, message, ARRAYLENGTH( message ), NULL, NULL );
32 #else // _UNICODE
33  char const* const message = error.ErrorMessage();
34 #endif // _UNICODE
35 
36  std::stringstream stream;
37  stream << file << " - line " << line << std::endl << '\t' << CollapseWhitespace( what ) << std::endl << '\t' << CollapseWhitespace( message );
38  m_what = stream.str();
39 }
40 
41 
42 WindowsException::~WindowsException() throw() {
43 }
44 
45 
46 const char* WindowsException::what() const throw() {
47 
48  return m_what.c_str();
49 }