22 ms·
Depending on where it crashed, the Python script would raise an exception. It would most likely be an `IoError`, `KeyError`, or `ValueError`. Then it would show
by scriptkiddy 9y ago
Depending on where it crashed, the Python script would raise an exception. It would most likely be an `IoError`, `KeyError`, or `ValueError`. Then it would show an error message with a line number, column number, and traceback. Using a debugger would allow you to step backwards through the traceback to determine if the error was caused by something further up the line or where the exception was raised.
All of Python's exceptions are an instance of `Exception`. In order to catch and handle any exception that can be raised, you can use a `try, except` block with the base `Exception` class. This, however, is bad practice as there may be some exceptions you want to ignore and, generally, you also want to print a different error message depending on which exception was raised.
- dep_b 9y agoSo the Python script proposed in this article really just skips all error checking and will die just the same as the hard unwrapped Rust version with the only benefit it actually produces a more user-friendly error and it doesn't look as ugly. I can't edit my reply anymore but the question was actually meant to be rhetorical rather than I really wanted an answer.
- scriptkiddy 9y ago> So the Python script proposed in this article really just skips all error checking Only if the programmer chooses to not handle exceptions, which is bad practice. >and will die just the same as the hard unwrapped Rust version with the only benefit it actually produces a more user-friendly error and it doesn't look as ugly. No, it won't die unless the programmer wants it to. In Python you can catch an exception and continue the operation in a different manner. In fact, it is common practice in a lot of Python libraries to use exceptions to determine the presence of data and act according to whether or not the exception occurred. If I'm not mistaken, I believe that this is common practice in most languages that utilize the exception pattern. > I can't edit my reply anymore but the question was actually meant to be rhetorical rather than I really wanted an answer. Well, you seem to not know a lot about exception handling in Python, so I hope I was at least a little helpful.
- deleted 9y ago[deleted]