If you want to play around with this stuff, you can first import sys,
and then insert this line in the except clause:
print repr(sys.exc_info())
(or some other way of getting the details out of the returned tuple.)
That will tell you exactly what brought you to the except clause.
On Feb 28, 200
[snip]
>
> (Although, I'm not sure what you meant by "working" in the below case,
> since your example doesn't exit the interpreter.)
> [snip]
>
>
> try:
>f = file('somefile_you_have.txt','r')
>sys.exit(0)
>
> except IOError:
>print "You had an error on file input"
Cecilia Alm wrote:
> I have two quick questions:
>
> 1) Why does sys.exit() not work in a try clause (but it does in the
> except clause)?
sys.exit raises an exception. That's how it exits program execution.
If you use it in a try block, the exception it raises will have no
effect because your e
When you call sys.exit() you're raising a SystemExit exception.
help(sys.exit)
Help on built-in function exit in module sys:
exit(...)
exit([status])
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the s