"Exceptions will fade away in modern languages"
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Fri Nov 27 12:52:37 UTC 2020
On Wednesday, 25 November 2020 at 17:15:14 UTC, Meta wrote:
> Rust has no exceptions (only `panic`, which aborts the current
> thread), and instead opts to use algebraic data types along
> with some light language support. Swift does something very
> similar.
Worth mentioning that the default behaviour for Rust's `panic` is
to unwind the stack. This means that panics are recoverable
errors in practice (e.g. the Tokio task-scheduling framework will
gracefully handle panics inside individual tasks).
IIRC libraries can specify in their build config if they rely on
the stack-unwinding behaviour, so that builds will fail if a
downstream requests the abort option (or vice versa). I believe
though that even in the abort case, the parent thread may still
be able to catch and recover from an aborted child thread. See
e.g.:
https://doc.rust-lang.org/nomicon/unwinding.html
So it's less that Rust has no exceptions, more that they don't
_call_ them exceptions, they are not conceptualized as "this is
allowed to fail", they don't distinguish different types of such
error, and depending on the build config the circumstances in
which they are recoverable are more or less constrained.
More information about the Digitalmars-d
mailing list