Using the try and except statements

When an exception is raised, the ordinary sequential exception of statements stops. The next sequential statement is not executed. Instead, the exception handlers are examined to find an except clause which matches the given exception's class. This search proceeds down the call stack from the current function to the function which called it. If an except clause is found which matches the exception, then ordinary sequential execution resumes in that except clause. When the except clause finishes, the try statement is also finished. From there, the normal sequential statement execution continues after the try statement.

If no except clause matches the given exception, the exception and the traceback information ...

Get Python Essentials 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.