THE EXCEPTION SYSTEM

We'll be looking at the specifics of the exception system shortly, but before we do that keep in mind the following:

  • Exceptions are used throughout Python – during the parsing process of a Python script, any faults in the syntax are highlighted by raising a SyntaxError exception. Exceptions in Python are not a bolt-on feature, they are used by the interpreter itself as a way of highlighting problems.

  • Exceptions are classes – all exceptions are based on the Exception class and follow a strict hierarchy. This allows you to trap a general exception such as ArithmeticError, or a more specific problem such as ZeroDivisionError.

  • Exceptions are “dumb” – exceptions can pass objects and error information, they are simply a semaphore ...

Get Perl To Python Migration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.