Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109448 > unrolled thread

Re: Catch exception with message?

Started byBen Finney <ben+python@benfinney.id.au>
First post2016-06-04 10:48 +1000
Last post2016-06-04 10:48 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Catch exception with message? Ben Finney <ben+python@benfinney.id.au> - 2016-06-04 10:48 +1000

#109448 — Re: Catch exception with message?

FromBen Finney <ben+python@benfinney.id.au>
Date2016-06-04 10:48 +1000
SubjectRe: Catch exception with message?
Message-ID<mailman.142.1465001407.1839.python-list@python.org>
Piyush Verma <114piyush@gmail.com> writes:

> But sometimes, we see same type of exception is present with different
> message.Is there a way to capture same exception with message
> filtering? Please help me to do this.

That's a nasty code smell. Why would you want your code to behave
differently depending on what the text of the message is? The message
should not change the semantic meaning of the exception type.

If there are exceptions that *mean* different things (i.e. that require
different handling), they should be different types.

See the Python 3 standard exception hierarchy for a good example.

-- 
 \        “The greatest tragedy in mankind's entire history may be the |
  `\       hijacking of morality by religion.” —Arthur C. Clarke, 1991 |
_o__)                                                                  |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web