sys.exit and exceptions (newbie question)
Greg Jorgensen
gregj at pobox.com
Thu Feb 1 14:28:43 EST 2001
More information about the Python-list mailing list
Thu Feb 1 14:28:43 EST 2001
- Previous message (by thread): sys.exit and exceptions (newbie question)
- Next message (by thread): sys.exit and exceptions (newbie question)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Functions that exit without giving the caller a chance to catch the exception are a very bad idea. Exception handling is good Python practice; forcing an un-catchable exit is not. In article <3a7998cf.869169328 at localhost>, victor at prodigy.net (Victor Muslin) wrote: > What is a pythonic idiom for forcing an immediate program termination? > sys.exit() does not do it, because it throws a SystemExit exception, > so if it is called within a try block, a generic except block is still > executed. Of course it is possible to specifically catch SystemExit, > as in the following example, but it is a pain. Moreover, one may want > to exit in a code that plugs into somebody else's code framed by try: > except: blocks. > > import sys > try: > print 'Exiting...' > sys.exit(0) > except SystemExit: > print 'System exit...' > except: > print 'Oops... except' > -- Greg Jorgensen Portland, Oregon, USA gregj at pobox.com Sent via Deja.com http://www.deja.com/
- Previous message (by thread): sys.exit and exceptions (newbie question)
- Next message (by thread): sys.exit and exceptions (newbie question)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list