[OT] - C++ exceptions are becoming more and more problematic

Atila Neves atila.neves at gmail.com
Fri Mar 4 12:34:02 UTC 2022


On Thursday, 3 March 2022 at 15:35:03 UTC, Paul Backus wrote:
> On Thursday, 3 March 2022 at 12:05:11 UTC, Atila Neves wrote:
>> On Friday, 25 February 2022 at 00:30:49 UTC, H. S. Teoh wrote:
>>>
>>> Go, Zig, Rust, and Odin all require explicit checking for 
>>> error returns.
>>
>> Nope: 
>> http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/reference/expressions/operator-expr.html#the-question-mark-operator
>>
>> Years ago, I justified my preference for exceptions because 
>> the rest of the call stack didn't have to be cluttered with 
>> "rethrowing". Having to pattern match is better, but still a 
>> pain. The macro solution they went with is the only one I know 
>> of that is as easy to use as exceptions without the associated 
>> baggage.
>
> Swift has similar syntax sugar with its "try" keyword:
>
> https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html
>
> And of course there are also more general-purpose language 
> features like Haskell's "do" notation [1] and Scala's "for" 
> comprehensions [2] that handle this as a special case.
>
> [1] https://en.m.wikibooks.org/wiki/Haskell/do_notation
> [2] https://docs.scala-lang.org/tour/for-comprehensions.html

I didn't know about Swift, thanks for the link.

I left out Haskell on purpose - do notation can do "anything" for 
certain values of "anything". Then people stack monad 
transformers 4 deep and I'm off to the hills. Or would be if I 
wrote Haskell, there's a reason I don't.


More information about the Digitalmars-d mailing list