Why no try-except-finally ?

KefX keflimarcusx at aol.comNOSPAM
Wed Nov 5 05:07:06 EST 2003


>Hang on, there is something wrong with what you say here. If you really had 
>the code you wrote above, and you put DeInit() in the except block and 
>again after it then any time an exception was thrown you would call DeInit 
>twice. Is this *really* what you wanted?

Err, no, it'd also exit with an error code in the except block (something I
hadn't written in at that moment because I had already realized it wasn't going
to work that way). My bad.

For now I rewrote it like this, just a modified version of what you suggested:

    err_code = 0
    try:
        game.Play()  # was PlayGame() before
    except:
        err_msg = "FATAL ERROR: " + sys.exc_info()[0]
        logger.critical(err_msg)
        err_code = 1

    DeInit()
    return err_code




More information about the Python-list mailing list