Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
error_handler.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11#pragma once
12
13#include <functional>
14#include <string>
15
16#include <kcenon/common/interfaces/logger_interface.h>
17#include <kcenon/common/interfaces/global_logger_registry.h>
18
19namespace kcenon::thread {
20
28public:
29 using error_callback = std::function<void(const std::string& context,
30 const std::string& error)>;
31
32 virtual ~error_handler() = default;
33
39 virtual void handle_error(const std::string& context,
40 const std::string& error) = 0;
41
47};
48
57private:
59
60public:
61 void handle_error(const std::string& context,
62 const std::string& error) override {
63 // Log the error using GlobalLoggerRegistry
64 auto logger = common::interfaces::GlobalLoggerRegistry::instance().get_default_logger();
65 if (logger) {
66 logger->log(common::interfaces::log_level::error, context + ": " + error);
67 }
68
69 // Call the callback if registered
70 if (callback_) {
71 callback_(context, error);
72 }
73 }
74
78};
79
80} // namespace kcenon::thread
Default error handler implementation.
void handle_error(const std::string &context, const std::string &error) override
Handle an error.
void set_error_callback(error_callback callback) override
Set a callback for error handling.
Error handler interface.
virtual void set_error_callback(error_callback callback)=0
Set a callback for error handling.
virtual ~error_handler()=default
std::function< void(const std::string &context, const std::string &error)> error_callback
virtual void handle_error(const std::string &context, const std::string &error)=0
Handle an error.
Represents an error in the thread system.
@ callback
Call user callback for custom decision.
Core threading foundation of the thread system library.
Definition thread_impl.h:17