By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

sys.exit versus raise SystemExit

P: n/a
Hi,

Is there any difference between calling sys.exit() and raise SystemExit?
Should I prefer one over the other?

Regards,

Will McGugan
--
blog: http://www.willmcgugan.com
Jan 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Will McGugan wrote:
Hi,

Is there any difference between calling sys.exit() and raise SystemExit?
Should I prefer one over the other?

Regards,

Will McGugan
--
blog: http://www.willmcgugan.com
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html

Jan 8 '07 #2

P: n/a
wi******@hotmail.com wrote:
>
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html
Oh I know. I was just wondering if there was some sort of subtle 'best
practice' recommendation that I wasnt aware of for using sys.exit over
raising the exception manually. In the same way that 'open' is prefered
over 'file', even though they appear to do the same thing.

Will
--
blog: http://www.willmcgugan.com
Jan 8 '07 #3

P: n/a
Will McGugan <wi**@willNOmcguganSPAM.comwrote:
wi******@hotmail.com wrote:
>>
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html
Oh I know. I was just wondering if there was some sort of subtle 'best
practice' recommendation that I wasnt aware of for using sys.exit over
raising the exception manually. In the same way that 'open' is prefered
over 'file', even though they appear to do the same thing.
'open' is preferred when you are opening a file, 'file' is preferred when
it is the type you want. That way you leave open the option to intercept
the 'open' action without interfering with tests against the type.

I guess in a similar way you should prefer the overridable sys.exit()
function rather than using the exception directly.
Jan 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.