exceptions == errors?

Skip Montanaro skip at pobox.com
Tue Apr 8 02:20:45 CEST 2003


    Mark> Are exceptions always considered errors, or there the same feeling
    Mark> as in C++ that exceptions can be used for non-error situations?

Exceptions are frequently used to signal non-error conditions.  For example,
they can be used to break out of nested loops:

    class Finished(exception): pass

    try:
        for foo in some_list:
            for bar in some_other_list:
                ...
                if conditions_met:
                    raise Finished
                ...
    except Finished:
        pass

Skip





More information about the Python-list mailing list