3 ms·
> ("randomly" as in: why is "open file" throwing an exception when file doesn't exist but "find substring" returns -1 when substring doesn't exist?) Because th
by joshuamorton 7y ago
> ("randomly" as in: why is "open file" throwing an exception when file doesn't exist but "find substring" returns -1 when substring doesn't exist?)
Because there can be lots of ways for `open` to throw an exception (encoding issues, not found, permissions, etc.). The underlying open syscall has 39 error codes. Python adds a few more failure modes atop that. I'd much rather deal with named error conditions than deal with return values -1 through -50.
Find substring can only fail in one way.
- incompatible 7y agoEven C can map the returns values -1 through -50 to symbolic constants, typically defined in preprocessor headers.
- joshuamorton 7y agoAbsolutely, but dealing with categories of errors is much harder with unstructured error codes.