The try Statement

The try statement specifies a way to handle exceptions. One form is the following:

try:
      suite
except expression-target:
      suite
except:
      suite

which can have one or many except clauses—the exception handlers. If an exception occurs in the try clause's suite of statements, an exception handler that best fits it will be invoked. An except clause that doesn't have an expression target can act as a catchall bucket. If an exception doesn't have a specific exception handler and an except clause without an expression target is present, the exception will go to that clause.

The Call Stack

A call stack represents the order of called functions. For example, if a module calls function A() and function A() calls function B() and function ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython 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.