#pragma once
#ifndef _EXCEPTION_
#define _EXCEPTION_
#ifndef RC_INVOKED
#include <yvals.h>
#include <type_traits>
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,_STL_WARNING_LEVEL)
#pragma warning(disable: _STL_DISABLED_WARNINGS)
#pragma warning(disable:
4455
4494
4619
4643
4702
4984
4988
)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
_CXX17_DEPRECATE_UNCAUGHT_EXCEPTION _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL uncaught_exception() noexcept;
bool
__cdecl
()
noexcept
;
_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL uncaught_exceptions() noexcept;
#if _HAS_EXCEPTIONS
#include <malloc.h>
#include <vcruntime_exception.h>
using
::
;
#ifndef _M_CEE_PURE
using
::
;
using
::
;
_NODISCARD inline terminate_handler __CRTDECL get_terminate() noexcept
inline
__cdecl
()
noexcept
{
return
(
());
}
#endif /* _M_CEE_PURE */
#if _HAS_UNEXPECTED
using
::
;
#ifndef _M_CEE_PURE
using
::
;
using
::
;
_NODISCARD inline unexpected_handler __CRTDECL get_unexpected() noexcept
inline
__cdecl
()
noexcept
{
return
(
());
}
#endif /* _M_CEE_PURE */
#endif /* _HAS_UNEXPECTED */
#else /* _HAS_EXCEPTIONS */
// CLASS exception
_STDEXT_BEGIN
class exception;
_STDEXT_END
_STD_BEGIN
using _STDEXT exception;
typedef void (__cdecl *_Prhand)(const exception&);
extern _CRTIMP2_NCEEPURE_IMPORT _Prhand _Raise_handler; // pointer to raise handler
_STD_END
_STDEXT_BEGIN
class exception
{ // base of all library exceptions
public:
static _STD _Prhand _Set_raise_handler(_STD _Prhand _Pnew)
{ // register a handler for _Raise calls
const _STD _Prhand _Pold = _STD _Raise_handler;
_STD _Raise_handler = _Pnew;
return (_Pold);
}
// this constructor is necessary to compile
// successfully header new for _HAS_EXCEPTIONS==0 scenario
explicit __CLR_OR_THIS_CALL exception(const char *_Message = "unknown", int = 1) noexcept
: _Ptr(_Message)
{ // construct from message string
}
__CLR_OR_THIS_CALL exception(const exception& _Right) noexcept
: _Ptr(_Right._Ptr)
{ // construct by copying _Right
}
exception& __CLR_OR_THIS_CALL operator=(const exception& _Right) noexcept
{ // assign _Right
_Ptr = _Right._Ptr;
return (*this);
}
virtual __CLR_OR_THIS_CALL ~exception() noexcept
{ // destroy the object
}
_NODISCARD virtual const char * __CLR_OR_THIS_CALL what() const noexcept
{ // return pointer to message string
return (_Ptr != nullptr ? _Ptr : "unknown exception");
}
void __CLR_OR_THIS_CALL _Raise() const
{ // raise the exception
if (_STD _Raise_handler != nullptr)
(*_STD _Raise_handler)(*this); // call raise handler if present
_Doraise(); // call the protected virtual
_RAISE(*this); // raise this exception
}
protected:
virtual void __CLR_OR_THIS_CALL _Doraise() const
{ // perform class-specific exception handling
}
protected:
const char *_Ptr; // the message pointer
};
// CLASS bad_exception
class bad_exception : public exception
{ // base of all bad exceptions
public:
__CLR_OR_THIS_CALL bad_exception(const char *_Message = "bad exception") noexcept
: exception(_Message)
{ // construct from message string
}
virtual __CLR_OR_THIS_CALL ~bad_exception() noexcept
{ // destroy the object
}
protected:
virtual void __CLR_OR_THIS_CALL _Doraise() const
{ // raise this exception
_RAISE(*this);
}
};
// CLASS bad_alloc
class bad_alloc : public exception
{ // base of all bad allocation exceptions
public:
__CLR_OR_THIS_CALL bad_alloc() noexcept
: exception("bad allocation", 1)
{ // construct from message string with no memory allocation
}
virtual __CLR_OR_THIS_CALL ~bad_alloc() noexcept
{ // destroy the object
}
private:
friend class bad_array_new_length;
__CLR_OR_THIS_CALL bad_alloc(const char *_Message) noexcept
: exception(_Message, 1)
{ // construct from message string with no memory allocation
}
protected:
virtual void __CLR_OR_THIS_CALL _Doraise() const
{ // perform class-specific exception handling
_RAISE(*this);
}
};
_STDEXT_END
_STD_BEGIN
// DUMMY FUNCTION DECLARATIONS
typedef void (__cdecl *terminate_handler)();
inline terminate_handler __CRTDECL set_terminate(terminate_handler) noexcept
{ // register a terminate handler
return nullptr;
}
inline void __CRTDECL terminate() noexcept
{ // handle exception termination
}
_NODISCARD inline terminate_handler __CRTDECL get_terminate() noexcept
{ // get current terminate handler
return (nullptr);
}
#if _HAS_UNEXPECTED
typedef void (__cdecl *unexpected_handler)();
inline unexpected_handler __CRTDECL set_unexpected(unexpected_handler) noexcept
{ // register an unexpected handler
return nullptr;
}
inline void __CRTDECL unexpected()
{ // handle unexpected exception
}
_NODISCARD inline unexpected_handler __CRTDECL get_unexpected() noexcept
{ // get current unexpected handler
return (nullptr);
}
#endif /* _HAS_UNEXPECTED */
using _STDEXT bad_alloc;
using _STDEXT bad_exception;
_STD_END
#endif /* _HAS_EXCEPTIONS */
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(_Out_ void*, _In_ const void*);
void
__cdecl
(
void
*,
const
void
*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrAssign(_Inout_ void*, _In_ const void*);
void
__cdecl
(
void
*,
const
void
*);
_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrCompare(_In_ const void*, _In_ const void*);
bool
__cdecl
(
const
void
*,
const
void
*);
_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrToBool(_In_ const void*);
bool
__cdecl
(
const
void
*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(_Inout_ void*, _Inout_ void*);
void
__cdecl
(
void
*,
void
*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(_Out_ void*);
void
__cdecl
__ExceptionPtrCurrentException
(
void
*);
[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrRethrow(_In_ const void*);
[[noreturn]]
void
__cdecl
(
const
void
*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopyException(
void
__cdecl
__ExceptionPtrCopyException
(
_Inout_ void*, _In_ const void*, _In_ const void*);
void
*,
const
void
*,
const
void
*);
class
{
public
:
()
noexcept
{
(
this
);
}
(
)
noexcept
{
(
this
);
}
()
noexcept
{
(
this
);
}
(
const
&
)
noexcept
{
(
this
, &
);
}
&
(
const
&
)
noexcept
{
(
this
, &
);
return
*
this
;
}
&
(
)
noexcept
{
;
(
this
, &
_Ptr
);
return
*
this
;
}
explicit
bool
()
const
noexcept
{
return
(
this
);
}
[[noreturn]]
void
()
const
{
(
this
);
}
static
()
noexcept
{
;
__ExceptionPtrCurrentException
(&
_Retval
);
return
_Retval
;
}
static exception_ptr _Copy_exception(_In_ void* _Except, _In_ const void* _Ptr)
static
(
void
*
,
const
void
*
)
{
;
if
(!
)
{
return
_Retval
;
}
__ExceptionPtrCopyException
(&
_Retval
,
,
);
return
_Retval
;
}
private
:
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif /* __clang__ */
void
*
;
void
*
;
#ifdef __clang__
#pragma clang diagnostic pop
#endif /* __clang__ */
};
inline
void
(
&
,
&
)
noexcept
{
(&
, &
);
}
_NODISCARD inline bool operator==(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept
inline
bool
(
const
&
,
const
&
)
noexcept
{
return
(&
, &
);
}
_NODISCARD inline bool operator==(nullptr_t, const exception_ptr& _Rhs) noexcept
inline
bool
(
,
const
&
)
noexcept
{
return
!
;
}
_NODISCARD inline bool operator==(const exception_ptr& _Lhs, nullptr_t) noexcept
inline
bool
(
const
&
,
)
noexcept
{
return
!
;
}
_NODISCARD inline bool operator!=(const exception_ptr& _Lhs, const exception_ptr& _Rhs) noexcept
inline
bool
(
const
&
,
const
&
)
noexcept
{
return
!(
);
}
_NODISCARD inline bool operator!=(nullptr_t _Lhs, const exception_ptr& _Rhs) noexcept
inline
bool
(
,
const
&
)
noexcept
{
return
!(
);
}
_NODISCARD inline bool operator!=(const exception_ptr& _Lhs, nullptr_t _Rhs) noexcept
inline
bool
(
const
&
,
)
noexcept
{
return
!(
);
}
_NODISCARD inline exception_ptr current_exception() noexcept
{
return
::
();
}
[[noreturn]] inline void rethrow_exception(_In_ exception_ptr _Ptr)
[[noreturn]]
inline
void
(
)
{
.
();
}
template
<
class
>
void
*
(
);
template<class _Ex> _NODISCARD exception_ptr make_exception_ptr(_Ex _Except) noexcept
template
<
class
>
(
)
noexcept
{
return exception_ptr::_Copy_exception(_STD addressof(_Except), __GetExceptionInfo(_Except));
return
::
(::
std
::
(
),
(
));
}
class
{
public
:
()
noexcept
: _Exc(_STD current_exception())
{
}
(
const
&)
noexcept
=
default
;
&
(
const
&)
noexcept
=
default
;
virtual
()
noexcept
{
}
[[noreturn]]
void
()
const
{
if
(
)
_STD rethrow_exception(_Exc);
else
}
_NODISCARD exception_ptr nested_ptr() const noexcept
{
return
(
);
}
private
:
;
};
template
<
class
,
class
>
struct
:
,
{
explicit
(
&&
)
: _Uty(_STD forward<_Ty>(_Arg)), nested_exception()
{
}
};
template
<
class
>
[[noreturn]]
inline
void
(
&&
,
)
{
using
=
<
>;
using
=
<
,
>;
_THROW(_Glued(_STD forward<_Ty>(_Arg)));
}
template
<
class
>
[[noreturn]]
inline
void
(
&&
,
)
{
_THROW(_STD forward<_Ty>(_Arg));
}
template
<
class
>
[[noreturn]]
inline
void
(
&&
)
{
typedef
<
>
;
<
<
>
&& !
<
,
>
&& !
<
>>
;
_Throw_with_nested(_STD forward<_Ty>(_Arg), _Tag);
}
#ifdef _CPPRTTI
template
<
class
>
inline
void
(
const
*
,
)
{
const
auto
=
dynamic_cast
<
const
*>(
);
if
(
_Nested
)
_Nested
->
();
}
template
<
class
>
inline
void
(
const
*,
)
{
}
template
<
class
>
inline
void
(
const
&
)
{
<
<
> && (!
<
,
>
||
<
*,
*>)>
;
_Rethrow_if_nested(_STD addressof(_Arg), _Tag);
}
#else /* _CPPRTTI */
template<class _Ty>
void rethrow_if_nested(const _Ty&) = delete; // requires /GR option
#endif /* _CPPRTTI */
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
#pragma warning(pop)
#pragma pack(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _EXCEPTION_ */