By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,626 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,626 IT Pros & Developers. It's quick & easy.

except AttributeError, TypeError:

P: n/a
What is the best way to except two errors, when the except handling in
both cases is the same?

"except:" would just except every error and not just those I want.

except Attribute error:
do_much_stuff
except TypeError:
do_the_same_stuff

is bad because of the duplication and

def do_it():
do_much_stuff
except Attribute error:
do_it()
except TypeError:
do_it()

would work but is rather unelegant? What is the best way to except to
errors with the same exception handling?

Thorsten
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Thorsten Kampe" <th******@thorstenkampe.de> wrote in message
news:19***************@thorstenkampe.de...
What is the best way to except two errors, when the except handling in
both cases is the same?

"except:" would just except every error and not just those I want.

except Attribute error:
do_much_stuff
except TypeError:
do_the_same_stuff

is bad because of the duplication and

def do_it():
do_much_stuff
except Attribute error:
do_it()
except TypeError:
do_it()

would work but is rather unelegant? What is the best way to except to
errors with the same exception handling?
except (AttributeError, TypeError):

John Roth
Thorsten

Jul 18 '05 #2

P: n/a
Thorsten Kampe <th******@thorstenkampe.de> writes:
What is the best way to except two errors, when the except handling in
both cases is the same?


The "except" keyword can take a list of exceptions in parentheses,

except (AttributeError, TypeError):
...

See the "Errors and Exceptions" chapter in the Python tutorial for
more details and examples.

--
Brian Gough

Network Theory Ltd,
Publishing the Python Manuals --- http://www.network-theory.co.uk/
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.