ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::ErrorHandler Class Reference

Central registry and dispatcher for task-error callbacks. More...

#include <error_handler.hpp>

Public Member Functions

auto add_callback (ErrorCallback callback) -> size_t
 Register an error callback.
void clear_callbacks ()
 Remove all registered error callbacks.
void handle_error (TaskError const &error)
 Dispatch an error to all registered callbacks.
auto error_count () const -> size_t
 Return the total number of errors handled since the last reset.
void reset_error_count ()
 Reset the cumulative error count to zero.

Detailed Description

Central registry and dispatcher for task-error callbacks.

ErrorHandler maintains an ordered list of ErrorCallback functions and invokes them whenever a task reports a failure through handle_error().

Thread safety
All public methods are guarded by an internal std::mutex, so the handler can be shared across threads (typically via std::shared_ptr).
Callback execution
  • Callbacks are invoked in the order they were registered (FIFO).
  • Callbacks run under the lock – keep them short and non-blocking to avoid contention with other threads that may call handle_error() or add_callback() concurrently.
  • If a callback itself throws, the exception is silently swallowed so that remaining callbacks still execute.
Limitations
add_callback() returns an index that identifies the callback, but there is no remove_callback() – only clear_callbacks() removes all callbacks at once. The error count returned by error_count() is monotonically increasing and is only reset by an explicit call to reset_error_count().

Definition at line 119 of file error_handler.hpp.

Member Function Documentation

◆ add_callback()

auto threadschedule::ErrorHandler::add_callback ( ErrorCallback callback) -> size_t
inline

Register an error callback.

Parameters
callbackCallable to invoke when a task throws.
Returns
Zero-based index (handle) of the newly added callback. There is currently no API to remove an individual callback; use clear_callbacks() to remove all.

Definition at line 130 of file error_handler.hpp.

◆ clear_callbacks()

void threadschedule::ErrorHandler::clear_callbacks ( )
inline

Remove all registered error callbacks.

After this call, handle_error() will still increment the error count but no callbacks will be invoked.

Definition at line 143 of file error_handler.hpp.

◆ error_count()

auto threadschedule::ErrorHandler::error_count ( ) const -> size_t
inlinenodiscard

Return the total number of errors handled since the last reset.

The count is monotonically increasing and is only set back to zero by an explicit call to reset_error_count().

Returns
Cumulative number of handle_error() invocations.

Definition at line 184 of file error_handler.hpp.

◆ handle_error()

void threadschedule::ErrorHandler::handle_error ( TaskError const & error)
inline

Dispatch an error to all registered callbacks.

Increments the internal error counter and then invokes every registered callback in order. If any callback throws, the exception is caught and silently discarded so that subsequent callbacks still run.

Parameters
errorDiagnostic information about the failed task.

Definition at line 158 of file error_handler.hpp.

◆ reset_error_count()

void threadschedule::ErrorHandler::reset_error_count ( )
inline

Reset the cumulative error count to zero.

Definition at line 193 of file error_handler.hpp.


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