4 ms·
You don't? If that's the case, can you explain why?
by justin_oaks 2y ago
You 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.