Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I honestly think exceptions will go down in history as a design mistake. Newer languages (eg Rust, Go) doesn't have them.

Exceptions make it incredibly difficult to be able to follow program flow. Most of the time you just log an exception and then either move on or exit. There's almost no actual handling of an except (other than maybe retrying). It gets even worse when people start using exceptions for control flow rather than errors.

One note about your example:

    > std::list <person*> people;
You wouldn't do this in C++. Why? Because ownership isn't clear meaning if people is cleaned up, it won't clean up the elements automatically. You could do:

    std::list<person> people;
but you have to be aware of copy semantics. You might do:

    std::list<std::unique_ptr<person>> people;
but that gets awkward too.


The differences between Go and Rust error handling is that Go doesn’t force you to handle its errors. Nothing bad happens if you just forget or don’t handle the error.

In Rust if you just unwrap it’s going to panic and in exception based languages it’s going to propagate until someone handles the error.

I personally don’t think Go error handling is going to go down in history as good.


I agree Rust's error handling is better and you can criticize some decisions in Go's error handling. I mean it also has these weird hybrid exception-like things (ie panics).

But the main point is that Go (and Rust) moved away from exception-as-control-flow that C++, C# and Java had adopted.


"exception-as-control-flow" is a misuse of exceptions. You can catch them just at strategic points and ignore them everywhere else.


I don't like Go error handling either (and I do like Rust) - but if the argument is against exceptions because of confusing flow, then there's a case for it in some languages I think - e.g. it's what you'd choose for Python if nobody had come up with exceptions (or they fell out of favour in time) for example.


Aside for not having to handle errors in Go, the type system itself makes error handling less useful. Rust's error handling is superior to Go's in every way I can think of.


It's literally impossible to write concurrent and highly-available code without exceptions.

You will be forced to write your own stack bubbling code. It's 2022, please don't write your own hand-made bespoke stack unwinding.


I think the GP was complaining that exceptions exist in the language, not suggesting that you can avoid them in C++. That’s why the other languages were listed.


> It's literally impossible to write concurrent and highly-available code without exceptions.

Do you have an example?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: