I have:
try:
...
except Exception, e:
print "Problem. %s" % str(e)
However, somewhere in try, i will need it to behave as if it encountered an Exception. Is it un-pythonic to do:
try:
...
raise Exception, 'Type 1 error'
...
except Exception, e:
print "Problem. Type 2 error %s" % str(e)
I think this is a bad design. If you need to take some action if (and only if) an exception wasn’t raised, that is what the
elseclause is there for. If you need to take some action unconditionally, that’s whatfinallyis for. here’s a demonstration:You need to factor the unconditional code into
finallyand put the other stuff inexcept/elseas appropriate.