From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Handling exceptions

Handling exceptions

- [Instructor] Exceptions are not to be feared but they do need to be reigned in. We saw a little bit about how to do this previously with the Try-Except statement. So here, we are catching this exception and then just returning it. So we don't get a stack trace or anything, but we do see that this zero division error instance is returned. There are a few interesting things you can do with this Try-Except pattern. For instance, if we don't care about getting the specific instance of the exception, we just maybe want to print something. We don't have to have the as e in order to catch an exception. There was some sort of error. And then that just prints out. Another useful thing you can do with this is the finally statement. So if I take my Try-Except block and add a finally to it, this will always execute. And you see that gets printed out. Finally statements can be useful because they will always execute no…

Contents