Reputation: 1256
I know that we can get the exception object if we use the 'as' syntax:-
try:
1/0
except ZeroDivisionError as e:
print "can not divide zero"
print(str(e))
I'd like to capture everything .... ex:-
try:
1/0
except * as e:
print "some error"
print(str(e))
Can that be done?
Upvotes: 0
Views: 45
Reputation: 60060
All of Python's exceptions are subclasses of Exception
, so you want:
try:
1/0
except Exception as e:
print "some error"
print(str(e))
# Output:
some error
integer division or modulo by zero
Upvotes: 5