I want to make an error on purpose so that it would go into the "except":
How do i do that?
I want to make an error on purpose so that it would go into the "except":
How do i do that?
Can't get much more pythonic than this:
raise Exception("I know python!")
See the raise statement docs for python if you'd like more info.
BTW You can throw any object
>>> for exc in "String Error", Exception("Real Exception"):
... try:
... raise exc
... except Exception,e :
... print "Caught:", e
... except:
... import traceback
... traceback.print_exc()
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
String Error
Caught: Real Exception
>>>