470,648 Members | 1,547 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

sys.exit versus raise SystemExit

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
3 10792

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
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
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.

Similar topics

12 posts views Thread by Ivan Voras | last post: by
5 posts views Thread by Simon Faulkner | last post: by
reply views Thread by gcash | last post: by
4 posts views Thread by Bryan | last post: by
1 post views Thread by Jia Lu | last post: by
3 posts views Thread by GinTon | last post: by
reply views Thread by Gary Robinson | last post: by
34 posts views Thread by Drake | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.