Python provides a very concise way to handle exceptions, but Python 2 and 3 each have their own distinct syntax for exception handling. In Python 3, catching exception objects requires the as keyword; raising exceptions with arguments requires parentheses; and strings cannot be used as exceptions. This chapter describes how to achieve neutral compatibility for raising, catching exceptions, and exception chaining.
Raising Exceptions
Python allows us to raise exceptions in several ways using the raise statement. Other languages may use throw. We can specify three parameters when using the ...