How to Handle Exceptions
How can we handle an exception thrown within a python process
We'll cover the following...
We'll cover the following...
Handling exceptions in Python is really easy. Let’s spend some time writing some examples that will cause exceptions. We will start with one of the most common computer science problems: division by zero.
If you think back to elementary math class, you will recall that you cannot divide by zero. In Python, this operation will cause an error, as you can see in the first half of the example. To catch the error, we wrap the operation with a try/except statement.
Bare Excepts
Here’s another way to catch the error:
This is not recommended! In Python, this is known ...