Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
9b321235
Commit
9b321235
authored
Dec 09, 2018
by
chili
Browse files
custom exception types
parent
19b128c2
Changes
6
Hide whitespace changes
Inline
Side-by-side
hw3d/ChiliException.cpp
0 → 100644
View file @
9b321235
/******************************************************************************************
* Chili Direct3D Engine *
* Copyright 2018 PlanetChili <http://www.planetchili.net> *
* *
* This file is part of Chili Direct3D Engine. *
* *
* Chili Direct3D Engine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Chili Direct3D Engine is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with The Chili Direct3D Engine. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#include "ChiliException.h"
#include <sstream>
ChiliException
::
ChiliException
(
int
line
,
const
char
*
file
)
noexcept
:
line
(
line
),
file
(
file
)
{}
const
char
*
ChiliException
::
what
()
const
noexcept
{
std
::
ostringstream
oss
;
oss
<<
GetType
()
<<
std
::
endl
<<
GetOriginString
();
whatBuffer
=
oss
.
str
();
return
whatBuffer
.
c_str
();
}
const
char
*
ChiliException
::
GetType
()
const
noexcept
{
return
"Chili Exception"
;
}
int
ChiliException
::
GetLine
()
const
noexcept
{
return
line
;
}
const
std
::
string
&
ChiliException
::
GetFile
()
const
noexcept
{
return
file
;
}
std
::
string
ChiliException
::
GetOriginString
()
const
noexcept
{
std
::
ostringstream
oss
;
oss
<<
"[File] "
<<
file
<<
std
::
endl
<<
"[Line] "
<<
line
;
return
oss
.
str
();
}
\ No newline at end of file
hw3d/ChiliException.h
0 → 100644
View file @
9b321235
/******************************************************************************************
* Chili Direct3D Engine *
* Copyright 2018 PlanetChili <http://www.planetchili.net> *
* *
* This file is part of Chili Direct3D Engine. *
* *
* Chili Direct3D Engine is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Chili Direct3D Engine is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with The Chili Direct3D Engine. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#pragma once
#include <exception>
#include <string>
class
ChiliException
:
public
std
::
exception
{
public:
ChiliException
(
int
line
,
const
char
*
file
)
noexcept
;
const
char
*
what
()
const
noexcept
override
;
virtual
const
char
*
GetType
()
const
noexcept
;
int
GetLine
()
const
noexcept
;
const
std
::
string
&
GetFile
()
const
noexcept
;
std
::
string
GetOriginString
()
const
noexcept
;
private:
int
line
;
std
::
string
file
;
protected:
mutable
std
::
string
whatBuffer
;
};
hw3d/Window.cpp
View file @
9b321235
...
...
@@ -18,6 +18,7 @@
* along with The Chili Direct3D Engine. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#include "Window.h"
#include <sstream>
// Window Class Stuff
...
...
@@ -124,4 +125,56 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
}
return
DefWindowProc
(
hWnd
,
msg
,
wParam
,
lParam
);
}
\ No newline at end of file
}
// Window Exception Stuff
Window
::
Exception
::
Exception
(
int
line
,
const
char
*
file
,
HRESULT
hr
)
noexcept
:
ChiliException
(
line
,
file
),
hr
(
hr
)
{}
const
char
*
Window
::
Exception
::
what
()
const
noexcept
{
std
::
ostringstream
oss
;
oss
<<
GetType
()
<<
std
::
endl
<<
"[Error Code] "
<<
GetErrorCode
()
<<
std
::
endl
<<
"[Description] "
<<
GetErrorString
()
<<
std
::
endl
<<
GetOriginString
();
whatBuffer
=
oss
.
str
();
return
whatBuffer
.
c_str
();
}
const
char
*
Window
::
Exception
::
GetType
()
const
noexcept
{
return
"Chili Window Exception"
;
}
std
::
string
Window
::
Exception
::
TranslateErrorCode
(
HRESULT
hr
)
noexcept
{
char
*
pMsgBuf
=
nullptr
;
DWORD
nMsgLen
=
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
nullptr
,
hr
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
reinterpret_cast
<
LPSTR
>
(
&
pMsgBuf
),
0
,
nullptr
);
if
(
nMsgLen
==
0
)
{
return
"Unidentified error code"
;
}
std
::
string
errorString
=
pMsgBuf
;
LocalFree
(
pMsgBuf
);
return
errorString
;
}
HRESULT
Window
::
Exception
::
GetErrorCode
()
const
noexcept
{
return
hr
;
}
std
::
string
Window
::
Exception
::
GetErrorString
()
const
noexcept
{
return
TranslateErrorCode
(
hr
);
}
hw3d/Window.h
View file @
9b321235
...
...
@@ -19,10 +19,24 @@
******************************************************************************************/
#pragma once
#include "ChiliWin.h"
#include "ChiliException.h"
class
Window
{
public:
class
Exception
:
public
ChiliException
{
public:
Exception
(
int
line
,
const
char
*
file
,
HRESULT
hr
)
noexcept
;
const
char
*
what
()
const
noexcept
override
;
virtual
const
char
*
GetType
()
const
noexcept
;
static
std
::
string
TranslateErrorCode
(
HRESULT
hr
)
noexcept
;
HRESULT
GetErrorCode
()
const
noexcept
;
std
::
string
GetErrorString
()
const
noexcept
;
private:
HRESULT
hr
;
};
private:
// singleton manages registration/cleanup of window class
class
WindowClass
...
...
@@ -52,4 +66,8 @@ private:
int
width
;
int
height
;
HWND
hWnd
;
};
\ No newline at end of file
};
// error exception helper macro
#define CHWND_EXCEPT( hr ) Window::Exception( __LINE__,__FILE__,hr )
\ No newline at end of file
hw3d/hw3d.vcxproj
View file @
9b321235
...
...
@@ -145,11 +145,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"Window.cpp"
/>
<ClCompile
Include=
"WindowsMessageMap.cpp"
/>
<ClCompile
Include=
"WinMain.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliWin.h"
/>
<ClInclude
Include=
"Window.h"
/>
<ClInclude
Include=
"WindowsMessageMap.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
9b321235
...
...
@@ -24,6 +24,9 @@
<ClCompile
Include=
"Window.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"ChiliException.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
...
@@ -35,5 +38,8 @@
<ClInclude
Include=
"Window.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"ChiliException.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment