Skip to Content
Perl To Python Migration
book

Perl To Python Migration

by Martin C. Brown
November 2001
Beginner
320 pages
5h 53m
English
Pearson Business
Content preview from Perl To Python Migration

EXCEPTION HANDLERS

The exception process uses the try statement in two different forms, the tryexceptelse statement and the tryfinally statement. We've already seen a few examples of the first format; the second format provides a simplified operation sequence when you want to act upon an exception, but not actually handle the exception. We'll look at some examples to make it clearer.

try…except…else

The first form of the try statement acts a bit like an if statement in reverse – you embed a block of code which is executed, and then a number of except statements account for exceptions if they occur. The basic format for this first form is:

try:
    BLOCK
except [EXCEPTION [, DATA...]]:
    BLOCK

else:

    BLOCK

The else block is optional.

When the Python ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Perl by Example

Perl by Example

Ellie Quigley
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 0201734885Purchase book