Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Stroika::Foundation::Execution::DeclareActivity< ACTIVITY > Class Template Reference

#include <Activity.h>

Public Member Functions

 DeclareActivity ()=delete
 

Detailed Description

template<typename ACTIVITY>
class Stroika::Foundation::Execution::DeclareActivity< ACTIVITY >

Push the argument Activity onto the current thread's Activity stack in the constructor, and pop it off in the destructor.

Example Usage
static constexpr Activity kBuildingThingy_ {"building thingy"sv };
try {
DeclareActivity declareActivity { &kBuildingThingy_ };
doBuildThing (); // throw any exception (that inherits from Exception<>)
}
catch (...) {
String exceptionMsg = Characters::ToString (current_exception ());
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:465
Note
these activities are captured via CaptureCurrentActivities() - when an ExceptionStringHelper subclass (any of the Stroika Exception classes) is constructed. For 3rd-party exceptions, consider wrapping with NestedException.

Definition at line 149 of file Activity.h.

Constructor & Destructor Documentation

◆ DeclareActivity()

template<typename ACTIVITY >
Stroika::Foundation::Execution::DeclareActivity< ACTIVITY >::DeclareActivity ( )
delete

The caller must always declare an Activity object whose address can be taken, and whose lifetime exceeds that of the DeclareActivity object.

Note
the Activity* argument MAY be nullptr, in which case this does nothing.
    This is allowed to facilitate examples like:
        \code
            DeclareActivity declareActivity { flag? &kSomeActivity_? nullptr }; // so we only conditionally declare the activity
        \endcode

    I considered using optional<ACTIVITY> - but tricky since we pass in pointer - and really not much point. This has practically zero
    overhead, and is easy enough to understand and use.

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