Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Catch exception with message? Date: Sat, 04 Jun 2016 10:48:33 +1000 Lines: 21 Message-ID: References: <85shwt4w4e.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de 2ofxnKZ1ZeJ4KjmfEE21iweOnRzOIOaRhGsMlF96XFhg== Cancel-Lock: sha1:j3UA/a3OFuUFnaDT0FxxLIXFRUA= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'differently': 0.07; 'nasty': 0.07; 'semantic': 0.07; 'behave': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'exception': 0.13; 'hierarchy': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:exception': 0.16; 'example.': 0.18; 'exceptions': 0.22; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'this.': 0.28; 'types.': 0.29; 'code': 0.30; 'is?': 0.33; 'text': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; '(i.e.': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'things': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'your': 0.60; 'entire': 0.61; 'different': 0.63; 'capture': 0.66; '1991': 0.84; '_o__)': 0.84; 'hijacking': 0.84; 'received:125': 0.84; 'subject:Catch': 0.91; '\xe2\x80\x9cthe': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <85shwt4w4e.fsf@benfinney.id.au> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:109448 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