Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Throw.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7
8#include "Throw.h"
9
10#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
13#endif
14
15using namespace Stroika::Foundation;
17using namespace Stroika::Foundation::Execution;
18
19#if qStroika_Foundation_Debug_DefaultTracingOn
20/*
21 ********************************************************************************
22 ********************* Execution::Private_::JustDbgTrace_ ***********************
23 ********************************************************************************
24 */
25void Execution::Private_::JustDbgTrace_ (const string& msg)
26{
27 DbgTrace ("{}"_f, String::FromNarrowSDKString (msg));
28}
29void Execution::Private_::JustDbgTrace_ (const wstring& msg)
30{
31 DbgTrace ("{}"_f, msg);
32}
33
34/*
35 ********************************************************************************
36 ************* Execution::Private_::ThrowingExceptionDbgTrace_ ******************
37 ********************************************************************************
38 */
39void Execution::Private_::ThrowingExceptionDbgTrace_ (const string& msg)
40{
41 if constexpr (qStroika_Foundation_Execution_Throw_TraceThrowpoint) {
42#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
43 DbgTrace ("Throwing exception: {} from {}"_f, String::FromNarrowSDKString (msg), Private_::GetBT_ws ());
44#else
45 DbgTrace ("Throwing exception: {}"_f, String{msg});
46#endif
47 }
48}
49void Execution::Private_::ThrowingExceptionDbgTrace_ (const wstring& msg)
50{
51 if constexpr (qStroika_Foundation_Execution_Throw_TraceThrowpoint) {
52#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
53 DbgTrace ("Throwing exception: {} from {}"_f, msg, Private_::GetBT_ws ());
54#else
55 DbgTrace ("Throwing exception: {}"_f, msg);
56#endif
57 }
58}
59
60/*
61 ********************************************************************************
62 ************ Execution::Private_::ReThrowingExceptionDbgTrace_ *****************
63 ********************************************************************************
64 */
65void Execution::Private_::ReThrowingExceptionDbgTrace_ (const string& msg)
66{
67 if constexpr (qStroika_Foundation_Execution_Throw_TraceThrowpoint) {
68#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
69 DbgTrace ("ReThrow: {} from {}"_f, String::FromNarrowSDKString (msg), Private_::GetBT_ws ());
70#else
71 DbgTrace ("ReThrow: {}"_f, String{msg});
72#endif
73 }
74}
75void Execution::Private_::ReThrowingExceptionDbgTrace_ (const wstring& msg)
76{
77 if constexpr (qStroika_Foundation_Execution_Throw_TraceThrowpoint) {
78#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
79 DbgTrace ("ReThrow: {} from {}"_f, msg, Private_::GetBT_ws ());
80#else
81 DbgTrace ("ReThrow: {}"_f, msg);
82#endif
83 }
84}
85#endif
86
87/*
88 ********************************************************************************
89 ******************** Execution::Private_::GetBT_s/GetBT_ws *********************
90 ********************************************************************************
91 */
92#if qStroika_Foundation_Execution_Throw_TraceThrowpointBacktrace
93string Execution::Private_::GetBT_s ()
94{
95 // KISS, and don't use string if you don't want truncation
96 wstring tmp = Debug::BackTrace::Capture (Debug::BackTrace::Options{1}); // skip this frame from stacktrace
97 string result;
98 for (wchar_t c : tmp) {
99 result += static_cast<char> (c);
100 }
101 return result;
102}
103wstring Execution::Private_::GetBT_ws ()
104{
105 // no need to use Thread::SuppressInterruptionInContext since not using any Stroika code that can throw
106 return Debug::BackTrace::Capture (Debug::BackTrace::Options{1}); // skip this frame from stacktrace
107}
108#endif
109
110string Execution::Private_::ToString_ (const type_info& s)
111{
112 return Characters::ToString (s).AsNarrowSDKString (Characters::eIgnoreErrors);
113}
#define DbgTrace
Definition Trace.h:309
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201