May 2018
Beginner to intermediate
282 pages
7h 58m
English
Exception handling syntax and functionality has been significantly improved in Python 3.
In Python 3, you cannot use the comma-separated syntax for the except clause. Use the as keyword instead:
|
Python 2 |
Python 3 and 2 |
try: pass except e, BaseException: pass |
try: passexcept e as BaseException: pass |
The new syntax is recommended for Python 2 as well.
In Python 3, all exceptions must be derived (directly or indirectly) from BaseException. In practice, you will create your custom exceptions by deriving from the Exception class.
As a major improvement in error reporting, if an exception occurs while handling an exception, the entire chain of exceptions is reported:
|
Python 2 |
Python ... |
Read now
Unlock full access