Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::operation_cancelled_exception Class Reference

Exception thrown when an operation is cancelled. More...

#include <cancellation_exception.h>

Inheritance diagram for kcenon::thread::operation_cancelled_exception:
Inheritance graph
Collaboration diagram for kcenon::thread::operation_cancelled_exception:
Collaboration graph

Public Member Functions

 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.
 
auto reason () const noexcept -> const cancellation_reason &
 Returns the cancellation reason.
 

Private Attributes

cancellation_reason reason_
 
std::string message_
 

Detailed Description

Exception thrown when an operation is cancelled.

This exception type represents a cancelled operation. It carries the cancellation_reason for inspection by catch handlers.

Note
As of v1.0, public APIs use common::VoidResult via check_cancelled() instead of throwing this exception directly.

Design Principles

  • Rich Information: Carries full cancellation_reason for debugging
  • Standard Compatible: Derives from std::exception
  • Thread Safe: All methods are const and safe for concurrent access

Usage Example

auto result = token.check_cancelled();
if (result.is_err()) {
LOG_INFO("Operation cancelled: {}", result.error().message);
return result;
}
do_work();
A template class representing either a value or an error.
See also
enhanced_cancellation_token::check_cancelled()
cancellation_reason

Definition at line 49 of file cancellation_exception.h.

Constructor & Destructor Documentation

◆ operation_cancelled_exception()

kcenon::thread::operation_cancelled_exception::operation_cancelled_exception ( cancellation_reason reason)
inlineexplicit

Constructs an exception with the given cancellation reason.

Parameters
reasonThe reason for the cancellation.

Definition at line 56 of file cancellation_exception.h.

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_ +=
68 }
69 }
auto reason() const noexcept -> const cancellation_reason &
Returns the cancellation reason.
static auto type_to_string(type t) -> std::string
Converts the reason type enum to a string.
type reason_type
The type of cancellation that occurred.
std::string message
Human-readable message describing the cancellation.

References kcenon::thread::cancellation_reason::message, message_, and reason_.

Member Function Documentation

◆ reason()

auto kcenon::thread::operation_cancelled_exception::reason ( ) const -> const cancellation_reason&
inlinenodiscardnoexcept

Returns the cancellation reason.

Returns
A const reference to the cancellation_reason.

Definition at line 84 of file cancellation_exception.h.

85 {
86 return reason_;
87 }

References reason_.

◆ what()

auto kcenon::thread::operation_cancelled_exception::what ( ) const -> const char*
inlinenodiscardoverridenoexcept

Returns a description of the exception.

Returns
A C-string describing the exception.

Definition at line 75 of file cancellation_exception.h.

76 {
77 return message_.c_str();
78 }

References message_.

Member Data Documentation

◆ message_

std::string kcenon::thread::operation_cancelled_exception::message_
private

Definition at line 91 of file cancellation_exception.h.

Referenced by operation_cancelled_exception(), and what().

◆ reason_

cancellation_reason kcenon::thread::operation_cancelled_exception::reason_
private

Definition at line 90 of file cancellation_exception.h.

Referenced by operation_cancelled_exception(), and reason().


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