"Exceptions will fade away in modern languages"

Dukc ajieskola at gmail.com
Thu Nov 26 04:41:57 UTC 2020


On Saturday, 21 November 2020 at 23:05:19 UTC, IGotD- wrote:
> I reacted to the comment of Walter Bright about exceptions in 
> the "Destroy All Memory Corruption" presentation. The point he 
> made that exceptions don't play well with compile time data 
> flow analysis. He also mentioned that he thinks that exception 
> will become obsolete in the future. Exceptions are used in many 
> languages today and even the newest ones so I can't see a trend 
> here.
>
> That raises the question what method is going to replace 
> exceptions in that case?
> Will D introduce an alternative method of error handler that 
> plays better with @live?

A (library-based) sum type used as error value, probably. That's 
what Rust does, except it also has language support for the 
concept. Because I personally don't like exceptions much, I have 
some experience from that approach (using TaggedAlgebraic). It 
feels somewhat cumbersome - Rust probably is better fit for that 
than we are. But D still can do more tricks C++, Java or C# can, 
probably. `with` and `final switch` statements are useful in my 
experience. As is the possibility to 
`sumTypeVariable.visit!(...)`, but it has the downside that you 
always exit that statement the same way -you can't `break` or 
`goto` out.

Why I don't like exceptions? I feel I am making my functions less 
general when using them. For example, when parsing XML and 
encountering a syntax error, if I throw on the error I 
essentially declare that my function is only intended for 
generally sound XML -it isn't intended to count or list syntax 
errors in a text full of them. Errors in return codes are use 
case agnostic in this regard. Perhaps this is one of the reasons 
why Walter considers exceptions an aged concept.


More information about the Digitalmars-d mailing list