FAQ
hello,

my script creates files that i need to delete if an exception is
thrown.

is this a good pythonic style to do this kind of cleanup in
sys.excepthook instead of inside except clause of a try block?

konstantin

Search Discussions

  • MRAB at Sep 23, 2009 at 3:54 pm

    akonsu wrote:
    hello,

    my script creates files that i need to delete if an exception is
    thrown.

    is this a good pythonic style to do this kind of cleanup in
    sys.excepthook instead of inside except clause of a try block?
    Speaking personally, I'd do the cleanup in the except clause if they
    needed to be deleted only if there was an exception; I'd use a finally
    clause or a 'with' context if they always had to be deleted, whether
    there was an exception or not.
  • Jean-Michel Pichavant at Sep 23, 2009 at 3:57 pm

    akonsu wrote:
    hello,

    my script creates files that i need to delete if an exception is
    thrown.

    is this a good pythonic style to do this kind of cleanup in
    sys.excepthook instead of inside except clause of a try block?

    konstantin
    def doIt():
    pass

    try:
    doIt()
    except Exception, exc:
    #cleaning up files



    I mean, what is the problem with try except ? It's pythonic. If you tell
    us what wrong with it in your case, we may spend time on hacking
    sys.excepthook.

    Jean-Michel
  • Akonsu at Sep 23, 2009 at 4:02 pm

    On Sep 23, 11:57?am, Jean-Michel Pichavant wrote:
    akonsu wrote:
    hello,
    my script creates files that i need to delete if an exception is
    thrown.
    is this a good pythonic style to do this kind of cleanup in
    sys.excepthook instead of inside except clause of a try block?
    konstantin
    def doIt():
    ? ? pass

    try:
    ? ? doIt()
    except Exception, exc:
    ? ? #cleaning up files

    I mean, what is the problem with try except ? It's pythonic. If you tell
    us what wrong with it in your case, we may spend time on hacking
    sys.excepthook.

    Jean-Michel
    thanks. nothing is wrong with try/except. i just already have an
    excepthook handler that uses logger to send emails if a critical error
    occurs, so i was just thinking that maybe i can add cleanup there. i
    agree, try/except makes more sense.

    konstantin

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 23, '09 at 3:28p
activeSep 23, '09 at 4:02p
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase