4 ms·
My issue with exceptions is also practical. If they didn't introduce significant stability issues, I'd have no problem. As it stands, it's impossible to write
by jesse__ 9mo ago
My issue with exceptions is also practical. If they didn't introduce significant stability issues, I'd have no problem. As it stands, it's impossible to write robust software that makes use of C++ exceptions.
> the compiler will require you to deal with it somehow in g
I agree, this is the sensible solution.
- yunnpp 9mo agoWhat stability issues?
- rauli_ 9mo agoUnchecked exceptions will eventually lead into programs crashing because some developer forgot to catch specific type of exception somewhere.
- drysine 9mo agoAnd developers never forget to check error codes.
- dan00 9mo agoLooking at code, it‘s easier to spot the missing check for an error code, than a not catched exceptions. Also error codes are part of the signature of a function, which exceptions aren‘t.
- drysine 8mo agoIf you need to wrap each call in try/catch, it's better to use return codes in some form or rethink the approach.
- listeria 9mo agomay I introduce you to the nodiscard attribute[1]? enum (class)? [[nodiscard]] Error { Ok, NoMem, ... }; [1]: https://en.cppreference.com/w/cpp/language/attributes/nodiscard.html https://en.cppreference.com/w/cpp/language/attributes/nodisc...
- drysine 9mo agoC attribute: nodiscard (since C23) [1] https://en.cppreference.com/w/c/language/attributes/nodiscard https://en.cppreference.com/w/c/language/attributes/nodiscar...
- senderista 9mo agoFWIW I’ve been using warn_unused_result in both gcc and clang since about 2020.
- drysine 8mo agoYep, partial remedies are available for quite some time.
- ahtihn 9mo agoThat seems like a better outcome than continuing when an error happened while thinking everything succeeded?
- yunnpp 8mo agoYes, but that's not a dichotomy. Languages like Java have function declare what exceptions they throw, and the caller must either catch it or also declare that it throws it. Gets cumbersome quickly, but I believe it's for the best to encode exceptions at the type system.