"Exceptions will fade away in modern languages"

Jacob Carlborg doob at me.com
Thu Nov 26 10:31:06 UTC 2020


On Wednesday, 25 November 2020 at 17:15:14 UTC, Meta wrote:

> This is well-trodden ground among D's competitors.
>
> 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.

No, Swift has dedicated syntax for error handling, just like D. 
The syntax looks very much like the syntax used for exceptions. 
The implementation doesn't use table based exceptions but instead 
builds on the Objective-C/Cocoa error handling style. Which is to 
return a bool to indicate success or failure and return the 
actual error through an out parameter. Any thing that is thrown 
need to implement the `Error` protocol. Which probably means that 
there is some for of type info used under the hood.

Zig uses a form of algebraic data type to return a value or an 
error. An error is represented as an error set, kind of like an 
enum. Zig provides syntax sugar on top this, which syntax looking 
very much like exceptions. The error handling in Zig looks pretty 
good, the only problem is that you can only throw error codes. 
It's not possible to provide any extra data with an error.

--
/Jacob Carlborg



More information about the Digitalmars-d mailing list