Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
cancellation_exception.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
12#include "cancellation_reason.h"
13
14#include <exception>
15#include <string>
16
17namespace kcenon::thread
18{
49 class operation_cancelled_exception : public std::exception
50 {
51 public:
57 : reason_(std::move(reason))
58 {
59 message_ = "Operation cancelled";
60 if (!reason_.message.empty())
61 {
62 message_ += ": " + reason_.message;
63 }
64 else
65 {
66 message_ +=
67 " (" + cancellation_reason::type_to_string(reason_.reason_type) + ")";
68 }
69 }
70
75 [[nodiscard]] auto what() const noexcept -> const char* override
76 {
77 return message_.c_str();
78 }
79
84 [[nodiscard]] auto reason() const noexcept -> const cancellation_reason&
85 {
86 return reason_;
87 }
88
89 private:
91 std::string message_;
92 };
93
94} // namespace kcenon::thread
Cancellation reason structure for enhanced cancellation tokens.
Exception thrown when an operation is cancelled.
auto reason() const noexcept -> const cancellation_reason &
Returns the cancellation reason.
operation_cancelled_exception(cancellation_reason reason)
Constructs an exception with the given cancellation reason.
auto what() const noexcept -> const char *override
Returns a description of the exception.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
STL namespace.
Holds information about why a cancellation occurred.
std::string message
Human-readable message describing the cancellation.