I know how to catch exceptions and print the message they returned:
class SelfDefinedException(Exception): pass
try:
message = "Hello World!"
raise SelfDefinedException(message)
except MyDefinedException, e:
print "MyDefinedException", e
This works good so far.
But how can I catch and print the message in a 'finally' clause?
class SelfDefinedException(Exception): pass
try:
message = "Hello World!"
raise SelfDefinedException(message)
except MyDefinedException, e:
print "MyDefinedException", e
finally:
# What goes here? So I can see what went wrong?
From several answers I understand, that this is not possible. Is it ok to do something like this?
class SelfDefinedException(Exception): pass
try:
message = "Hello World!"
raise SelfDefinedException(message)
except MyDefinedException, e:
print "MyDefinedException", e
except Exception, e:
# Hopefully catches all messages except for the one of MyDefinedException
print "Unexpected Exception raised:", e