4 ms·
Error handling is a fundamental concept that must be tought in every programming course and it is usually neglected. > Catching exceptions is a bad way to hand
by gozzoo 6y ago
Error handling is a fundamental concept that must be tought in every programming course and it is usually neglected.
> Catching exceptions is a bad way to handle errors.
I don't agree. If used properly exceptions are a very elegant way to handle extraordinary conditions and events. Of course we have to ignore the horrible mess Java created with their checked exceptions.
I realized the power of exceptions while I was reading the book UNIX Network Programming by Richard Stevents. I was stuned to see that in some examples most of the code was not implementing the logic, but handling errors. Exceptions would make such implementations very consise and easy to read and comprehend.
> Nowadays there are much better mechanisms of error handling, possible errors should be type-checked at compile-time. Languages that do not use exceptions by default will be ranked higher.
What are they? I don't like the golang aproach each function to return 2 values (result and error code) if this is what the author means.
- folkrav 6y ago> What are they? I don't like the golang aproach each function to return 2 values (result and error code) if this is what the author means. If anything the golang approach is creating even more boilerplate, thing the author complained about more than once f, err := os.Open("some_file.ext") if err != nil { log.Fatal("Oh noes") } x10000 across the codebase
- bdavisx 6y agoI have to say though that I prefer a functional approach w/ Either/Result<T,E> over Exceptions now that I've done both. With both you can choose to ignore an exception and have it "pass" up to a higher level, but the functional approach is more specific - with Exceptions and how they are implemented in most languages you have to look @ the source code to see what exception(s) could be thrown.