Exceptions
But what are the exceptions? You can think of them as warning messages letting us know about computation issues and halting the computation. For example, when we're trying to divide by zero, the computer knows it's wrong and raises a corresponding ZeroDivisionError type error, stopping the process. We can raise exceptions from within our own code by using the raise keyword. There are a handful of built-in exception types, such as KeyError, ValueError, and IndexError. The only significant difference between these is the name, which helps us to understand and differentiate between issues. All those exceptions inherit from the base exception type—Exception. Each exception can be raised with supporting text if you so desire. Consider ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access