Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Stroika::Foundation::Execution::Exception< BASE_EXCEPTION > Class Template Reference

Exception<> is a replacement (subclass) for any std c++ exception class (e.g. the default 'std::exception'), which adds UNICODE String support. More...

#include <Exceptions.h>

Inheritance diagram for Stroika::Foundation::Execution::Exception< BASE_EXCEPTION >:
Stroika::Foundation::Execution::ExceptionStringHelper

Public Member Functions

 Exception ()=delete
 construct with just a message - BASE_EXCEPTION gets whatever it minimally needs.
 
virtual const char * what () const noexcept override
 
- Public Member Functions inherited from Stroika::Foundation::Execution::ExceptionStringHelper
 ExceptionStringHelper ()=delete
 activities default to NULLOPT - meaning "not specified" - which is different from "specified, and there were none".
 
nonvirtual Characters::String GetBasicErrorMessage () const
 
nonvirtual Characters::String GetFullErrorMessage () const
 
nonvirtual optional< Containers::Stack< Activity<> > > GetActivities () const
 
nonvirtual void ImbueActivities (const optional< Containers::Stack< Activity<> > > &activities)
 Set, replace, or clear the activity stack. Any already-computed message text is discarded, since it depends on these.
 
template<typename T >
nonvirtual T As () const
 

Protected Member Functions

template<typename... BASE_EXCEPTION_ARGS>
 Exception (const Characters::String &reasonForError, BASE_EXCEPTION_ARGS... baseExceptionArgs)
 
- Protected Member Functions inherited from Stroika::Foundation::Execution::ExceptionStringHelper
nonvirtual const char * _PeekAtNarrowSDKString () const
 

Detailed Description

template<derived_from< exception > BASE_EXCEPTION = exception>
class Stroika::Foundation::Execution::Exception< BASE_EXCEPTION >

Exception<> is a replacement (subclass) for any std c++ exception class (e.g. the default 'std::exception'), which adds UNICODE String support.

Stroika's Exception<> class is fully interoperable with the normal C++ exception classes, but its use offers two benefits: o It guarantees that UNICODE messages (including things like filenames) are properly preserved in the exception message, even if the system default code page (locale) does not allow representing those characters.

o It integrates neatly with the Stroika 'Activity' mechanism, whereby you declare current 'activities' on the stack and these are automatically integrated into exceptions thrown with Execution::Throw (), to provide clearer messages (e.g. instead of getting the error message o "(errno: 13)" OR o "Permission denied" Stroika returns something like: o "Permission denied {errno: 13} while binding to INADDR_ANY:80, while constructing static content webserver."

See also
Activity<>
DeclareActivity
Example Usage
static constexpr Activity kBuildingThingy_ {"building thingy"sv };
try {
doBuildThing (); // Execution::Throw () any Exception<>
}
catch (...) {
Assert (exceptionMsg.Contains (kBuildingThingy_.AsString ())); // exception e while building thingy...
}
String ToString(T &&t, ARGS... args)
Return a debug-friendly, display version of the argument: not guaranteed parsable or usable except fo...
Definition ToString.inl:424
Note
Satisfies: o Exception<std::exception>{msg} - default-constructible o Exception<std::bad_alloc>{msg} - default-constructible o Exception<std::runtime_error>{msg} - requires a what_arg o Exception<std::logic_error>{msg} - requires a what_arg o Exception<std::out_of_range>{msg} - requires a what_arg
Deliberately NOT std::system_error: it needs an error_code, not a string, so it satisfies neither constraint and must use the protected delegating ctor below -
See also
SystemErrorException. (No static_assert for this one, because it is not portable: libstdc++ declares system_error (error_code = error_code ()), so THERE it is default-constructible and this ctor does match, yielding a useless empty code. MSVC has no such default. Do not rely on either behaviour.)

Definition at line 219 of file Exceptions.h.

Constructor & Destructor Documentation

◆ Exception() [1/2]

template<derived_from< exception > BASE_EXCEPTION = exception>
Stroika::Foundation::Execution::Exception< BASE_EXCEPTION >::Exception ( )
delete

construct with just a message - BASE_EXCEPTION gets whatever it minimally needs.

Two overloads with mutually exclusive constraints, because the std exception types split into two groups and NEITHER spelling covers both: some are default-constructible, and some instead require a what_arg (and have no default ctor). The latter get "" - they need some string and do not care which, since

See also
what () is overridden to return the Stroika message regardless.

◆ Exception() [2/2]

template<derived_from< exception > BASE_EXCEPTION>
template<typename... BASE_EXCEPTION_ARGS>
Stroika::Foundation::Execution::Exception< BASE_EXCEPTION >::Exception ( const Characters::String &  reasonForError,
BASE_EXCEPTION_ARGS...  baseExceptionArgs 
)
explicitprotected

For BASE_EXCEPTION classes with constructors OTHER than just 'message' - you cannot use a 'using X = Exception(x)' but a subclass which uses this delegating method.

Definition at line 89 of file Exceptions.inl.

Member Function Documentation

◆ what()

template<derived_from< exception > BASE_EXCEPTION>
const char * Stroika::Foundation::Execution::Exception< BASE_EXCEPTION >::what ( ) const
overridevirtualnoexcept

Provide a 'c string' variant of the exception message. Convert the UNICODE string argument to a narrow-string (multibyte) in the current locale encoding.

Definition at line 95 of file Exceptions.inl.


The documentation for this class was generated from the following files: