Many languages prioritize runtime safety by forcing users to handle (or annotate) the error cases for operations that can fail.
This works well for I/O and complex algorithms, but how should common fallible operations, like division and array access, be handled? Every a / b
can technically fail if b
is zero, and every list[index]
can fail if index
is out of range.
However, those operations are far too widespread to surround each instance with explicitcumbersome error handling, or annotating with "can throw division by zero".
How can a general-purpose programming language have this sort of operation without creating too much boilerplate for users, and without giving up safety with runtime panics?
Bonus points if the solution is usable for integer overflow, since it includes almost all arithmetic operations.