2 ms·
But once you've accepted unchecked exceptions (and paid the cost of the having them), it just doesn't make sense to only use them only for bugs. For example, it
by eeereerews 6y ago
But once you've accepted unchecked exceptions (and paid the cost of the having them), it just doesn't make sense to only use them only for bugs. For example, it is better to
try:
x = json['foo']['bar'][i]
catch OOB:
handle error
than to
if not (json is a dict and
'foo' in json and
json['foo'] is a dict and
...):
handle error
x = json['foo']['bar'][i]
even though in the former, unchecked exceptions are used for non-bugs.
- nicoburns 6y agoThe idea is that for bugs you don't even need a try-catch (or maybe one around your entire program). And pattern matching and functions like `map` make the second case much nicer.