libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
exception.hpp
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3
**
4
** This library is free software; you can redistribute it and/or
5
** modify it under the terms of the GNU Lesser General Public
6
** License as published by the Free Software Foundation; either
7
** version 2.1 of the License, or (at your option) any later version.
8
**
9
** This library is distributed in the hope that it will be useful,
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
** Lesser General Public License for more details.
13
**
14
** You should have received a copy of the GNU Lesser General Public
15
** License along with this library; if not, write to the Free Software
16
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*/
18
19
#
pragma
once
20
21
#
include
"DumpWinMsg.hpp"
22
23
namespace
jmmcg
{
namespace
LIBJMMCG_VER_NAMESPACE {
namespace
NTUtils {
24
25
/// Handy for use in source files.
26
#
define
JMMCG_MAKE_WEXCPT_SRC1
(
_JMMCG_EXCPT_MSG
)
jmmcg
::
LIBJMMCG_VER_NAMESPACE
::
win_exception
(
(
_JMMCG_EXCPT_MSG
)
,
JMMCG_FUNCTION
(
void
)
,
__REV_INFO__
)
27
/// Handy for use in header files.
28
#
define
JMMCG_MAKE_WEXCPT_HDR1
(
_JMMCG_EXCPT_MSG
,
_JMMCG_REVISION_HDR
)
jmmcg
::
LIBJMMCG_VER_NAMESPACE
::
win_exception
(
(
_JMMCG_EXCPT_MSG
)
,
JMMCG_FUNCTION
(
void
)
,
JMMCG_REVISION
(
_JMMCG_REVISION_HDR
)
)
29
30
class
win_exception
:
public
crt_exception
<
ppd
::
generic_traits
::
MS_Win32
,
ppd
::
heavyweight_threading
> {
31
public
:
32
typedef
crt_exception
<
ppd
::
generic_traits
::
MS_Win32
,
ppd
::
heavyweight_threading
>
base_t
;
33
34
win_exception
(
const
tstring &r,
const
info::function &f,
const
info::revision &ri)
35
:
base_t
(
r
,
f
,
ri
),
win_err
(::
GetLastError
()) {
36
}
37
win_exception
(
const
tostringstream &r,
const
info::function &f,
const
info::revision &ri)
38
:
base_t
(
r
,
f
,
ri
),
win_err
(::
GetLastError
()) {
39
}
40
win_exception
(
const
tstring &r,
const
unsigned
long
we,
const
info::function &f,
const
info::revision &ri)
41
:
base_t
(
r
,
f
,
ri
), win_err(we) {
42
}
43
win_exception
(
const
tostringstream &r,
const
unsigned
long
we,
const
info::function &f,
const
info::revision &ri)
44
:
base_t
(
r
,
f
,
ri
), win_err(we) {
45
}
46
win_exception
(
const
win_exception
&ex)
47
:
base_t
(
ex
), win_err(ex.win_err) {
48
}
49
virtual
50
~
win_exception
()
noexcept
(
true
) {
51
}
52
53
static
inline
tstring
__fastcall
54
StrFromWinErr
(
const
unsigned
long
win_err
) {
55
tostringstream ss;
56
ss<<_T(
"Windows error: code=0x"
)<<std::hex<<win_err<<_T(
", string: '"
)<<NTUtils::DumpWinMessage(win_err)<<_T(
"'."
);
57
return
ss.str();
58
};
59
60
/**
61
\todo Implement using the advice given in "Standard C++ IOStreams and Locales" by A.Langer & K.Kreft, page 170.
62
*/
63
friend
inline
tostream
&
__fastcall
64
operator
<<(
tostream
&
o
,
const
win_exception
&
e
) {
65
return
o<<e.to_string();
66
}
67
68
protected
:
69
virtual
inline
const
tstring
__fastcall
70
to_string
()
const
{
71
tostringstream ss;
72
ss<<base_t::to_string()
73
<<StrFromWinErr(win_err)<<std::endl;
74
return
ss.str();
75
}
76
77
private
:
78
const
unsigned
long
win_err;
79
80
void
operator=(
win_exception
const
&)=
delete
;
81
};
82
83
} } }
experimental
NT-based
NTSpecific
exception.hpp
Generated on Tue May 11 2021 17:31:21 for libjmmcg by
1.9.2