Exception Handlers

You will write exception handlers to trap the runtime errors in your executing code. You use try/except blocks to write your exception handlers:

Syntax:

try:

#code that may cause error/exception.

except:

#handles if exception occur.

A task which can raise an exception is placed inside the try block and a code that handles the exceptions are placed under the except block.

Note: A try statement can have multiple except clauses.