First page Back Continue Last page Overview Graphics

Functional Principle of try-except

First, the try clause between the try and the except keywords is executed.

If no exception occurs, the except clause is skipped.

If an exception occurs during execution of the try clause, the rest of the clause is skipped. If the type of the exception matches the exception named after the except keyword, the except clause is executed, and then execution continues after the try statement.

If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no handler is found, it is an unhandled exception and execution stops with a message.