by cletus · 4y ago · 0 comments
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.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.
But the main point is that Go (and Rust) moved away from exception-as-control-flow that C++, C# and Java had adopted.
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.
Do you have an example?