Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.04; 'subject:Python': 0.06; 'exception,': 0.09; 'pep': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '3.3,': 0.16; 'attributes.': 0.16; 'from:addr:pobox.com': 0.16; 'from:addr:skip': 0.16; 'indexerror:': 0.16; 'subject:exception': 0.16; 'subject:handling': 0.16; 'suggestion.': 0.16; 'tuple': 0.16; 'exception': 0.16; 'index': 0.16; 'sender:addr:gmail.com': 0.17; 'looked': 0.18; 'bit': 0.19; 'stack': 0.19; '>>>': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'skip': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'handling': 0.26; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'raise': 0.29; 'message- id:@mail.gmail.com': 0.30; '"",': 0.31; '3.2': 0.31; 'apparently': 0.31; 'closer': 0.31; 'division': 0.31; 'exceptions': 0.31; 'file': 0.32; 'another': 0.32; '(most': 0.33; 'alone': 0.33; 'maybe': 0.34; "can't": 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; "i'll": 0.36; 'recent': 0.39; 'itself': 0.39; 'full': 0.61; 'range': 0.61; 'more': 0.64; 'was:': 0.91; 'tomorrow': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=24OQ9slQOOu6HKN2lfb+CZ/9khacJc5ThafBcB2PJ0c=; b=PX6sn9JBUot1+DYe7By81XTYjtvsdZlMXCWRs7BxcU1hzzJ5t/7340PNq6p5Rsib7s 4ld8sHRxTyQrWvQbRPKS1QG78SUob+5W64JFH0y5J13HytyOzoJ6CbTi425MaHTPvoBw VWO4zVep8fE1fsn+AtQHbr6Igyjcha37z+VCbggNGGO9LAogvHLUAAJlmOCtv4DSPyYY zxZnC97oA9IEh2KIZxZ5mhrhoeL7RujhbDFwpyZmdVIIcVtjIel/rTmrlXv9eczgwOKe JXZ6iLKWYbaLtlUslWg6bivmy4/R56z9VLYMYNa9nsZJT47hzyOHkqFftfIocWa/5T22 CjPQ== MIME-Version: 1.0 X-Received: by 10.52.23.113 with SMTP id l17mr7767145vdf.23.1377579636391; Mon, 26 Aug 2013 22:00:36 -0700 (PDT) Sender: skip.montanaro@gmail.com In-Reply-To: <521C19F0.50605@stoneleaf.us> References: <521C0B62.1030004@mrabarnett.plus.com> <521C19F0.50605@stoneleaf.us> Date: Tue, 27 Aug 2013 00:00:36 -0500 X-Google-Sender-Auth: VP7XW8DdTkS2zxQ8dfTY0TPk6Yg Subject: Re: Missing something on exception handling in Python 3 From: Skip Montanaro To: Ethan Furman Content-Type: text/plain; charset=UTF-8 Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377579638 news.xs4all.nl 15886 [2001:888:2000:d::a6]:37527 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53030 I found this question/answer on Stack Overflow: http://stackoverflow.com/questions/15123137 but after fiddling around with it, I can't find a solution that works for Python 3.2 and 3.3, let alone 2.x. In 3.2, exceptions have both __cause__ and __context__ attributes. I tried setting both to None (in 3.2), but I still get the full double traceback: >>> try: 1/0 ... except ZeroDivisionError: ... exc = TypeError() ... exc.__context__ = None ... exc.__cause__ = None ... raise exc ... Error in sys.excepthook: IndexError: tuple index out of range Original exception was: Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 6, in TypeError The sys.excepthook error is because I have a custom interactive sys.excepthook, which is itself apparently broken in Python 3.2. I've looked at PEP 409 and 415, but just get more confused. *sigh* Maybe I'll try again tomorrow when I've had a bit of sleep... and take a closer look at Ethan's suggestion. Skip