Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
HRESULTErrorException.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_Platform_Windows_HRESULTErrorException_h_
5#define _Stroika_Foundation_Execution_Platform_Windows_HRESULTErrorException_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#if qStroika_Foundation_Common_Platform_Windows
10#include <Windows.h>
11#else
12#error "WINDOWS REQUIRED FOR THIS MODULE"
13#endif
14
15#include "Stroika/Foundation/Common/Common.h"
16
17#include "Stroika/Foundation/Execution/Exceptions.h"
18#include "Stroika/Foundation/Execution/Throw.h"
19
22}
23
25
26 /**
27 * Return a reference the the HRESULT error category object (windows only). This object lives forever (like other error categories).
28 */
29 const error_category& HRESULT_error_category () noexcept;
30
31 /**
32 * Translate a standard C++ (or Stroika) exception into the appropriate HRESULT to return
33 */
34#define CATCH_AND_HANDLE_EXCEPTIONS_IN_HRESULT_FUNCTION() \
35 catch (HRESULT hr) \
36 { \
37 return hr; \
38 } \
39 catch (const system_error& h) \
40 { \
41 if (h.code ().category () == Stroika::Foundation::Execution::Platform::Windows::HRESULT_error_category ()) { \
42 return h.code ().value (); \
43 } \
44 if (h.code ().category () == system_category ()) { \
45 return (HRESULT_FROM_WIN32 (h.code ().value ())); \
46 } \
47 return DISP_E_EXCEPTION; \
48 } \
49 catch (const bad_alloc&) \
50 { \
51 return E_OUTOFMEMORY; \
52 } \
53 catch (...) \
54 { \
55 return DISP_E_EXCEPTION; \
56 }
57
58 /**
59 * if hr did not SUCCCEED, then throw HRESULTErrorException
60 */
61 void ThrowIfErrorHRESULT (HRESULT hr);
62
63}
64
66 namespace Private_ {
67 using ConstVoidStar = const void*;
68 }
69
70 /**
71 * \brief Template specialization for ThrowIfNull (), for thing being thrown HRESULT - really throw HRESULTErrorException
72 */
73 template <>
74 void ThrowIfNull (const Private_::ConstVoidStar& p, const HRESULT& hr);
75
76}
77
78/*
79 ********************************************************************************
80 ***************************** Implementation Details ***************************
81 ********************************************************************************
82 */
83#include "HRESULTErrorException.inl"
84
85#endif /*_Stroika_Foundation_Execution_Platform_Windows_HRESULTErrorException_h_*/
basic_string< SDKChar > SDKString
Definition SDKString.h:38
void ThrowIfNull(const Private_::ConstVoidStar &p, const HRESULT &hr)
Template specialization for ThrowIfNull (), for thing being thrown HRESULT - really throw HRESULTErro...