4#include "Stroika/Foundation/StroikaPreComp.h"
8#if qStroika_Foundation_Common_Platform_Windows
15#include "Stroika/Foundation/Linguistics/MessageUtilities.h"
18#include "TimeOutException.h"
20#include "Exceptions.h"
23using namespace Characters;
24using namespace Execution;
38 if (activities.empty ()) {
39 return reasonForError;
42 auto tmp = Linguistics::MessageUtilities::Manager::sThe.RemoveTrailingSentencePunctuation (reasonForError);
45 for (
auto i = activities.begin (); i != activities.end ();) {
48 if (i == activities.end ()) {
49 sb << tmp.second.value_or (
"."sv);
66 : fActivities_{activities}
67 , fRawErrorMessage_{reasonForError}
68 , fFullErrorMessage_{mkMessage_ (reasonForError, activities)}
69 , fSDKCharString_{fFullErrorMessage_.AsNarrowSDKString (eIgnoreErrors)}
78NestedException::NestedException (
const exception_ptr& basedOnException)
88#if qStroika_Foundation_Common_Platform_Windows
92#pragma comment(lib, "Wininet.lib")
95optional<String> TryToOverrideDefaultWindowsSystemCategoryMessage_ (error_code errCode)
97 if (errCode.category () == system_category ()) {
98 switch (errCode.value ()) {
99 case ERROR_NOT_ENOUGH_MEMORY:
100 return "Not enough memory to complete that operation (ERROR_NOT_ENOUGH_MEMORY)"sv;
101 case ERROR_OUTOFMEMORY:
102 return "Not enough memory to complete that operation (ERROR_OUTOFMEMORY)"sv;
103 case WSAEADDRNOTAVAIL:
104 return "Socket address not available (WSAEADDRNOTAVAIL)"sv;
105 case ERROR_INTERNET_INVALID_URL:
106 return "ERROR_INTERNET_INVALID_URL"sv;
107 case ERROR_INTERNET_CANNOT_CONNECT:
108 return "Failed to connect to internet URL (ERROR_INTERNET_CANNOT_CONNECT)"sv;
109 case ERROR_INTERNET_NAME_NOT_RESOLVED:
110 return "ERROR_INTERNET_NAME_NOT_RESOLVED"sv;
111 case ERROR_INTERNET_INCORRECT_HANDLE_STATE:
112 return "ERROR_INTERNET_INCORRECT_HANDLE_STATE"sv;
113 case ERROR_INTERNET_TIMEOUT:
114 return "Operation timed out (ERROR_INTERNET_TIMEOUT)"sv;
115 case ERROR_INTERNET_CONNECTION_ABORTED:
116 return "ERROR_INTERNET_CONNECTION_ABORTED"sv;
117 case ERROR_INTERNET_CONNECTION_RESET:
118 return "ERROR_INTERNET_CONNECTION_RESET"sv;
119 case ERROR_HTTP_INVALID_SERVER_RESPONSE:
120 return "Invalid Server Response (ERROR_HTTP_INVALID_SERVER_RESPONSE)"sv;
121 case ERROR_INTERNET_PROTOCOL_NOT_FOUND: {
123 if (::InternetGetConnectedState (&r, 0) and (r & INTERNET_CONNECTION_OFFLINE) == 0) {
124 return "ERROR_INTERNET_PROTOCOL_NOT_FOUND"sv;
127 return "ERROR_INTERNET_PROTOCOL_NOT_FOUND (offline mode)"sv;
135Characters::String Execution::Private_::SystemErrorExceptionPrivate_::mkMsg_ (error_code errCode)
137#if qStroika_Foundation_Common_Platform_Windows
139 if (optional<String> o = TryToOverrideDefaultWindowsSystemCategoryMessage_ (errCode)) {
151 if (errCode.category () == generic_category ()) {
152 sb +=
"{{errno: {}}}"_f(errCode.value ());
154 else if (errCode.category () == system_category ()) {
155#if qStroika_Foundation_Common_Platform_POSIX
156 sb +=
"{{errno: {}}}"_f(errCode.value ());
157#elif qStroika_Foundation_Common_Platform_Windows
158 sb +=
"{{Windows error: {}}}"_f(errCode.value ());
160 sb +=
"{{system error: {}}}"_f(errCode.value ());
169void Execution::Private_::SystemErrorExceptionPrivate_::TranslateException_ (error_code errCode)
172 if (errCode == errc::not_enough_memory) {
175 if (errCode == errc::timed_out) {
178#if qCompilerAndStdLib_Winerror_map_doesnt_map_timeout_Buggy
179 if (errCode.category () == system_category ()) {
180 switch (errCode.value ()) {
182 case ERROR_INTERNET_TIMEOUT:
190#if qStroika_Foundation_Common_Platform_Windows && qStroika_Foundation_Debug_AssertionsChecked
191 if (errCode.category () == system_category ()) {
192 switch (errCode.value ()) {
193 case ERROR_NOT_ENOUGH_MEMORY:
194 case ERROR_OUTOFMEMORY:
196 case ERROR_INTERNET_TIMEOUT:
210unique_ptr<exception> Execution::Private_::SystemErrorExceptionPrivate_::TranslateExceptionQuietly_ (error_code errCode)
213 if (errCode == errc::not_enough_memory) {
214 return make_unique<bad_alloc> ();
216 if (errCode == errc::timed_out) {
217 return make_unique<TimeOutException> (errCode);
219#if qCompilerAndStdLib_Winerror_map_doesnt_map_timeout_Buggy
220 if (errCode.category () == system_category ()) {
221 switch (errCode.value ()) {
223 case ERROR_INTERNET_TIMEOUT:
224 return make_unique<TimeOutException> ();
236optional<error_code> Execution::GetAssociatedErrorCode (
const exception_ptr& e)
noexcept
239 rethrow_exception (e);
241 catch (
const system_error& se) {
#define AssertNotReached()
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
static String FromNarrowSDKString(const char *from)
ExceptionStringHelper()=delete
NestedException contains a new higher level error message (typically based on argument basedOnExcepti...
static const TimeOutException kThe
String ToString(T &&t, ARGS... args)
Return a debug-friendly, display version of the argument: not guaranteed parsable or usable except fo...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...