Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.106 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'context': 0.05; 'statements': 0.09; 'python': 0.10; 'subject:when': 0.16; 'wrote:': 0.16; 'of.': 0.18; '2015': 0.20; 'aug': 0.20; 'header :In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; "i'm": 0.30; 'code': 0.30; 'tue,': 0.34; 'received:10.0': 0.34; 'could': 0.35; 'replace': 0.35; 'something': 0.35; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'no.': 0.62; 'charset:windows-1252': 0.62; 'leaving': 0.63; 'managers': 0.63; 'million': 0.74; 'sounds': 0.76; 'instrument': 0.95 Date: Wed, 12 Aug 2015 18:05:00 +0200 From: "Sven R. Kunze" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Hooking Mechanism when Entering and Leaving a Try Block References: <55CA6D7F.1060705@mail.de> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 584 X-purgate-ID: 154282::1439395504-00000778-8B01B06E/0/0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439395514 news.xs4all.nl 2938 [2001:888:2000:d::a6]:38488 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95288 Unfortunately, no. :( It should work out of the box with no "let me replace all my try-except statements in my 10 million line code base". On 12.08.2015 17:32, Ian Kelly wrote: > On Tue, Aug 11, 2015 at 3:47 PM, Sven R. Kunze wrote: >> is there something like a hook that a Python module could register to in >> order to 'trace' the entering and leaving of arbitrary try blocks? > Not that I'm aware of. > > However, it sounds like context managers might do what you want. You > would just need to instrument your try blocks by adding with blocks.