<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2019.  All rights reserved
 */
#include "../StroikaPreComp.h"

#include <cstdio>

#if qPlatform_Windows
#include <Windows.h>
#include <wininet.h> // for error codes
#endif

#include "../IO/FileAccessException.h"

#include "Throw.h"
#include "TimeOutException.h"

#include "ErrNoException.h"

using namespace Stroika;
using namespace Stroika::Foundation;

using namespace Characters;
using namespace Execution;

using Debug::TraceContextBumper;

// Comment this in to turn on aggressive noisy DbgTrace in this module
//#define   USE_NOISY_TRACE_IN_THIS_MODULE_       1

/*
 ********************************************************************************
 ***************************** SystemException **********************************
 ********************************************************************************
 */
Characters::String SystemException::mkMsg_ (error_code errCode)
{
    return Characters::String::FromNarrowSDKString (errCode.message ());
}

Characters::String SystemException::mkMsg_ (error_code errCode, const Characters::String& message)
{
    return message + L": "sv + mkMsg_ (errCode);
}

#if !qPlatform_POSIX
void SystemException::ThrowPOSIXErrNo (int errNo)
{
    Require (errNo != 0);
    // @todo see errno_ErrorException::Throw () for additional needed mappings
    switch (static_cast<errc> (errNo)) {
        case errc::not_enough_memory: {
#if USE_NOISY_TRACE_IN_THIS_MODULE_
            DbgTrace ("SystemException::ThrowPOSIXErrNo (0x%x) - translating errc::not_enough_memory to bad_alloc", errNo);
#endif
            Throw (bad_alloc ());
        } break;
        case errc::timed_out: {
#if USE_NOISY_TRACE_IN_THIS_MODULE_
            DbgTrace ("SystemException::ThrowPOSIXErrNo (0x%x) - translating errc::not_enough_memory to TimeOutException", errNo);
#endif
            Throw (TimeOutException::kThe);<commit_msg>improved formatting of SystemError default exception messages<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2019.  All rights reserved
 */
#include "../StroikaPreComp.h"

#include <cstdio>

#if qPlatform_Windows
#include <Windows.h>
#include <wininet.h> // for error codes
#endif

#include "../Characters/Format.h"
#include "../IO/FileAccessException.h"

#include "Throw.h"
#include "TimeOutException.h"

#include "ErrNoException.h"

using namespace Stroika;
using namespace Stroika::Foundation;

using namespace Characters;
using namespace Execution;

using Debug::TraceContextBumper;

// Comment this in to turn on aggressive noisy DbgTrace in this module
//#define   USE_NOISY_TRACE_IN_THIS_MODULE_       1

/*
 ********************************************************************************
 ***************************** SystemException **********************************
 ********************************************************************************
 */
Characters::String SystemException::mkMsg_ (error_code errCode)
{
    return Characters::String::FromNarrowSDKString (errCode.message ());
}

Characters::String SystemException::mkMsg_ (error_code errCode, const Characters::String& message)
{
	if (errCode.category () == system_category ()
#if qPlatform_POSIX
		or errCode.category () == generic_category ()
#endif
		) {
#if qPlatform_POSIX
		return message + L": "sv + Characters::Format (L"{errno %d}", errCode.value ());
#elif qPlatform_Windows
		return message + L": "sv + Characters::Format (L"{Windows error %d}", errCode.value ());
#else
		return message + L": "sv + Characters::Format (L"{system error %d}", errCode.value ());
#endif
	}
	return message + L": "sv + Characters::Format (L"{%s %d}", Characters::String::FromNarrowSDKString (errCode.category ().name ()).c_str (), errCode.value ());
}

#if !qPlatform_POSIX
void SystemException::ThrowPOSIXErrNo (int errNo)
{
    Require (errNo != 0);
    // @todo see errno_ErrorException::Throw () for additional needed mappings
    switch (static_cast<errc> (errNo)) {
        case errc::not_enough_memory: {
#if USE_NOISY_TRACE_IN_THIS_MODULE_
            DbgTrace ("SystemException::ThrowPOSIXErrNo (0x%x) - translating errc::not_enough_memory to bad_alloc", errNo);
#endif
            Throw (bad_alloc ());
        } break;
        case errc::timed_out: {
#if USE_NOISY_TRACE_IN_THIS_MODULE_
            DbgTrace ("SystemException::ThrowPOSIXErrNo (0x%x) - translating errc::not_enough_memory to TimeOutException", errNo);
#endif
            Throw (TimeOutException::kThe);
{'fraction_non_alphanumeric': 0.21049107142857143, 'fraction_numerical': 0.005357142857142857, 'mean_word_length': 5.249651324965132, 'pattern_counts': {'":': 5, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2493993', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1305, 'n_words': 316}