Comments by "xybersurfer" (@xybersurfer) on "Why I Prefer Exceptions To Errors" video.
-
2
-
2
-
2
-
2
-
2
-
2
-
2
-
1
-
1
-
@justgame5508 yes, there are typical circumstances that a program can't or shouldn't recover from, but this is ultimately dependent on the program. it's even dependent on the calling function. yes, invalid user input is recoverable when you use it in a form because the user can simply try again, but invalid user input in an unattended background job is usually not recoverable. failing to read from IO due to insufficient privileges is recoverable, in the rare case that you can read from other IO. as you said, it depends on the context.
the caller is the context. this becomes very obvious when writing a library. for me Exceptions are simply an easy way to end the control flow, when i can't fulfill what the caller asked. the caller can decide whether it wants to recover, by catching the Exception. my claim is that errors, are not recoverable in most contexts. so the caller doesn't have to do anything to let the Exception propagate by default. this saves a lot of (forgotten) error handling logic and magic return values (potential bugs) throughout the call stack, and that is the big advantage.
also dealing with invalid user input in a form is a bit of a special case because it often involves gathering all the errors to show to the user and not immediately ending the control flow. but if i don't yet want to end the control flow when encountering an error then i simply won't throw an Exception, until i've gathered the errors. personally, i usually only use Exceptions for the individual errors when the code is used in other place that need that. i think it's the job of languages and frameworks to make this less awkward and more performant.
unfortunately a lot of times languages and frameworks make the decision for you, that you should be using Error Values instead of Exceptions. but that's a separate matter.
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
@justgame5508 yes, there are typical circumstances that a program can't or shouldn't recover from, but this is ultimately dependent on the program. it's even dependent on the calling function. yes, invalid user input is recoverable when you use it in a form because the user can simply try again, but invalid user input in an unattended background job is usually not recoverable. failing to read from IO due to insufficient privileges is recoverable, in the rare case that you can read from other IO. as you said, it depends on the context.
the caller is the context. this becomes very obvious when writing a library. for me Exceptions are simply an easy way to end the control flow, when i can't fulfill what the caller asked. the caller can decide whether it wants to recover, by catching the Exception.
my claim is that errors, are not recoverable in most contexts. so the caller doesn't have to do anything to let the Exception propagate by default. this saves a lot of (forgotten) error handling logic and magic return values (potential bugs) throughout the call stack, and that is the big advantage.
also dealing with invalid user input in a form is a bit of a special case because it often involves gathering all the errors to show to the user and not immediately ending the control flow. but if i don't yet want to end the control flow when encountering an error then i simply won't throw an Exception, until i've gathered the errors. personally, i usually only use Exceptions for the individual errors when the code is used in other place that need that. i think it's the job of languages and frameworks to make this less awkward and more performant.
unfortunately a lot of times languages and frameworks make the decision for you, that you should be using Error Values instead of Exceptions. but that's a separate matter.
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1
-
1