News for hackers. Stuff that matters.
Re:Errors – Gotta Catch 'Em All by otabdeveloper1 on Thursday April 04, 2019 @08:34AM (#19571405)
> I disagree with this, on a very strong and deep sense.

That's because you're inexperienced.

> All possible behaviors should be treated on equal footing, using the control structures of your language.

That's impossible if you're dealing with a system composed of multiple interacting abstraction layers.

An error inside a function precondition is not the same as an error crashing a thread of execution, which in turn is not the same as an error in logical consistency communicating between different services.

The "equal footing" you're talking about can only exist if you're dealing with very simple and linear programs.

Re:Errors – Gotta Catch 'Em All by JoshuaAshton on Thursday April 04, 2019 @08:58AM (#19571687)
> That's because you're inexperienced.

That's fairly rude to the guy, and doesn't make your point any stronger.

I've worked with exceptions before, it leads to try/catch spaghetti code.

You can't possibly know instantly all the exceptions to handle for a function (given it calls other functions w/ exceptions), whereas, if it returns a fixed bunch of error codes, then you can know why that specific function failed and handle appropriately.

Doesn't help that (language) exceptions typically have awful codegen.

There's a reason nobody uses them in game-dev.

Re:Errors – Gotta Catch 'Em All by yorwba on Thursday April 04, 2019 @09:17AM (#19571909)
> You can't possibly know instantly all the exceptions to handle for a function (given it calls other functions w/ exceptions),

You also can't possibly know all error codes to handle for a function if it calls other functions returning error codes, unless a type system enforces that for you. In which case you should compare to a language where the type system enforces that all exceptions are handled.

Re:Errors – Gotta Catch 'Em All by JoshuaAshton on Thursday April 04, 2019 @09:34AM (#19572062)
> You also can't possibly know all error codes to handle for a function if it calls other functions returning error codes

You aren't using error codes or documenting correctly. You get a choice whether the error propogates upstream

Re:Errors – Gotta Catch 'Em All by maccard on Thursday April 04, 2019 @10:02AM (#19572375)
I can make the same argument for exceptions - You're not documenting correctly. You also have the choice to ignore and fail with exceptions.

Example: you have a method which requests a file from disk, but it fails to load for some reason. With error codes, you force all callers of your resource loader to explicitly handle the failure case at the point of failure, or you lose all context on the error. If you just bubble the error up, you're manually doing exceptions.

With exceptions, the code that requests a file can assume it succeeds if it doesn't have enough context to handle the erorr, and you can handle at a higher level and still know what happened.

Re:Errors – Gotta Catch 'Em All by yorwba on Thursday April 04, 2019 @09:54AM (#19572282)
Exceptions can be documented just as well, and you have the same choice whether the error propagates upstream, only the default is different.
Re:Errors – Gotta Catch 'Em All by JoshuaAshton on Thursday April 04, 2019 @10:06AM (#19572431)
The default idea behind exceptions is silly and as I stated before, they typically get generated to some horrific code
Re:Errors – Gotta Catch 'Em All by joshuagvk on Thursday April 04, 2019 @09:17AM (#19571889)
I might be misunderstanding, but doesn't this

> You can't possibly know instantly all the exceptions to handle for a function (given it calls other functions w/ exceptions), whereas, if it returns a fixed bunch of error codes, then you can know why that specific function failed and handle appropriately.

presume that, despite not being able to know all exceptions to handle in advance, you somehow have knowledge of all error conditions in the event that you're using error codes?

Re:Errors – Gotta Catch 'Em All by enriquto on Thursday April 04, 2019 @09:35AM (#19572070)
> presume that, despite not being able to know all exceptions to handle in advance, you somehow have knowledge of all error conditions in the event that you're using error codes?

I guess that it is indeed the case. If you call one function, you can read the documentation of said function and read about its return values, including error codes. This specification cannot not change if one of the libraries nested deep within this function is replaced. However, with exceptions, if you use a new implementation of a deeply nested function it may raise a new exception that nobody was aware of at the time of writing the outermost functions.

Re:Errors – Gotta Catch 'Em All by JoshuaAshton on Thursday April 04, 2019 @09:35AM (#19572072)
Usually documentation tends to have this, or you can look at the function and immediately know what it will return, whereas with exceptions any passthrough errors are transparent.
Re:Errors – Gotta Catch 'Em All by otabdeveloper1 on Friday April 05, 2019 @07:47AM (#19581585)
> You can't possibly know instantly all the exceptions to handle for a function

And you never should. That indeed is horrible design.

What you do need is a separation between 'exceptions that cause hard failure' v.s. 'exceptions that can lead to soft restarts'.

You can easily separate them using common sense just looking at where your interface is located.