7 ms·
Article's about a guy who doesn't like using try catch as control flow
by strombofulous 2y ago
Article's about a guy who doesn't like using try catch as control flow
- InfiniteRand 2y agoApparently he finds null checking better
- nox101 2y ago"Exception" has a meaning. Exceptions are supposed to be used for just that, unexpected situations. Not being able to parse something is not an exception. It's a normal thing. RegEx doesn't throw an exception when there's no match. Array.indexOf doesn't throw an exception when it doesn't find a something. It's really nice to able to go into the debugger and say "stop on all exceptions" and not be spammed with the wrong use of exceptions And so, it's nice that we'll have `URL.parse`
- valicord 2y agoIf you're expecting a string to be a URL, failing to parse it as a URL is indeed an unexpected situation.
- maxbond 2y agoAn invalid URL in a config file is exceptional. An invalid URL typed in by a user or from an external source (eg the body of an API request or inside of some HTML) is Tuesday.
- justin_oaks 2y agoYou don't? If that's the case, can you explain why?
- wewtyflakes 2y agoNull checking can be fine if a failure mode is unambiguous. However, if an operation can fail for many reasons, it can be helpful to carry that information around in an object. For example with URL parsing, it might be nice to be able to know why parsing failed. Was it the lack of protocol? Bad path format? Bad domain format? Bad query format? Bad anchor format? This information could theoretically be passed back using an exception object, but this information is eliminated if null is returned.
- mrkeen 2y agoExceptions and null both require the caller to 'deal with it' verbosely, so neither saves lines of code. But the only thing more annoying than a loud failure (exceptions) is a silent failure (null) which keeps executing.