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


Groups > comp.lang.python > #109448

Re: Catch exception with message?

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Catch exception with message?
Date 2016-06-04 10:48 +1000
Message-ID <mailman.142.1465001407.1839.python-list@python.org> (permalink)
References <CAJV9OM_eDYJHsq1J7N9mYQEyqRsUR1S7LOJWZ8+XGEJ_h3CHYw@mail.gmail.com> <85shwt4w4e.fsf@benfinney.id.au>

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web