Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Execution/Platform/Windows/Exception.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#if qStroika_Platform_Windows
7#include <Windows.h>
8
9#include <shellapi.h>
10#include <winerror.h>
11#else
12#error "WINDOWS REQUIRED FOR THIS MODULE"
13#endif
14
16#include "Stroika/Foundation/Common/Common.h"
17#include "Stroika/Foundation/Containers/Common.h"
19#if qStroika_Platform_Windows
20#include "Stroika/Foundation/Execution/Platform/Windows/HRESULTErrorException.h"
21#endif
23
24#include "Exception.h"
25
26using namespace Stroika::Foundation;
28using namespace Stroika::Foundation::Debug;
29using namespace Stroika::Foundation::Execution;
30using namespace Stroika::Foundation::Execution::Platform;
32
33/*
34 ********************************************************************************
35 ***************************** ThrowIfShellExecError ****************************
36 ********************************************************************************
37 */
39{
42 int errCode = reinterpret_cast<int> (r);
43 DISABLE_COMPILER_MSC_WARNING_END (4311)
44 DISABLE_COMPILER_MSC_WARNING_END (4302)
45 if (errCode <= 32) {
46 DbgTrace ("ThrowIfShellExecError (0x{:x}) - throwing exception"_f, errCode);
47 switch (errCode) {
48 case 0:
49 ThrowSystemErrNo (ERROR_NOT_ENOUGH_MEMORY); // The operating system is out of memory or resources.
50 case ERROR_FILE_NOT_FOUND:
51 ThrowSystemErrNo (ERROR_FILE_NOT_FOUND); // The specified file was not found.
52 case ERROR_PATH_NOT_FOUND:
53 ThrowSystemErrNo (ERROR_PATH_NOT_FOUND); // The specified path was not found.
54 case ERROR_BAD_FORMAT:
55 ThrowSystemErrNo (ERROR_BAD_FORMAT); // The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image).
56 case SE_ERR_ACCESSDENIED:
57 ThrowError (error_code{E_ACCESSDENIED, HRESULT_error_category ()}); // The operating system denied access to the specified file.
58 case SE_ERR_ASSOCINCOMPLETE:
59 ThrowSystemErrNo (ERROR_NO_ASSOCIATION); // The file name association is incomplete or invalid.
60 case SE_ERR_DDEBUSY:
61 ThrowSystemErrNo (ERROR_DDE_FAIL); // The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
62 case SE_ERR_DDEFAIL:
63 ThrowSystemErrNo (ERROR_DDE_FAIL); // The DDE transaction failed.
64 case SE_ERR_DDETIMEOUT:
65 ThrowSystemErrNo (ERROR_DDE_FAIL); // The DDE transaction could not be completed because the request timed out.
66 case SE_ERR_DLLNOTFOUND:
67 ThrowSystemErrNo (ERROR_DLL_NOT_FOUND); // The specified dynamic-link library (DLL) was not found.
68 //case SE_ERR_FNF: throw (Platform::Windows::Exception (ERROR_FILE_NOT_FOUND)); // The specified file was not found.
69 case SE_ERR_NOASSOC:
70 ThrowSystemErrNo (ERROR_NO_ASSOCIATION); // There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
71 case SE_ERR_OOM:
72 ThrowSystemErrNo (ERROR_NOT_ENOUGH_MEMORY); // There was not enough memory to complete the operation.
73 //case SE_ERR_PNF: throw (Platform::Windows::Exception (ERROR_PATH_NOT_FOUND)); // The specified path was not found.
74 case SE_ERR_SHARE:
75 ThrowSystemErrNo (ERROR_INVALID_SHARENAME); //
76 default: {
77 // Not sure what error to report here...
78 ThrowSystemErrNo (ERROR_NO_ASSOCIATION);
79 }
80 }
81 }
82}
83
84/*
85 ********************************************************************************
86 *********** Execution::RegisterDefaultHandler_invalid_parameter ****************
87 ********************************************************************************
88 */
89namespace {
90 /*
91 * Because of Microsoft's new secure-runtime-lib - we must provide a handler to catch errors (shouldn't occur - but in case.
92 * We treat these largely like ASSERTION errors, but then translate them into a THROW of an exception - since that is
93 * probably more often the right thing todo.
94 */
95 void invalid_parameter_handler_ ([[maybe_unused]] const wchar_t* expression, [[maybe_unused]] const wchar_t* function,
96 [[maybe_unused]] const wchar_t* file, [[maybe_unused]] unsigned int line, [[maybe_unused]] uintptr_t pReserved)
97 {
99 L"invalid_parameter_handler", "Func='{}', expr='{}', file='{}', line={}."_f, function, expression, file, line)};
100 Assert (false);
101 ThrowSystemErrNo (ERROR_INVALID_PARAMETER);
102 }
103}
105{
106 (void)_set_invalid_parameter_handler (invalid_parameter_handler_);
107}
#define DbgTrace
Definition Trace.h:327
#define Stroika_Foundation_Debug_OptionalizeTraceArgs(...)
Definition Trace.h:288
void ThrowError(error_code ec)
throw a SystemErrorException with the given error_code - or std::bad_alloc for errc::not_enough_memor...