Standard Library
class CancelledException
The error delivered to a task that has been cancelled.
since 0.1.0-alpha.1linuxwindowswasm
- bases
Exception,ICancelledException
Overview
A cancelled task receives it at its next await, and only there; a task is never interrupted in the middle of running. Its message is task cancelled. It is an ordinary exception: catch it by class or by ICancelledException, or let it end the task. A task group absorbs it when it joins its tasks, so cancellation is not reported as a program error. It is not a RuntimeException.
Examples
try {
throw CancelledException("stopped");
} catch (RuntimeException e) {
console.writeln("runtime");
} catch (CancelledException e) {
console.writeln("cancelled: ${e.message}");
}
cancelled: stopped
Constructors
new
new(string msg)Creates a cancellation error with a message.
Parameters
- msg
- The text describing the cancellation.
Examples
CancelledException e = CancelledException("task cancelled");
console.writeln(e.message);
task cancelled
See also
- ICancelledException — The interface of the error that reports that a task was cancelled.
- IException — The interface that every thrown value must implement.