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


Groups > comp.lang.python > #80109

Re: When using a decorator exceptions raised reference the decorator not the function

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <nestorjb@gmail.com>
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; 'subject:not': 0.03; 'decorator': 0.09; 'exception.': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; '2.7': 0.14; 'called,': 0.16; 'email addr:udel.edu&gt;': 0.16; 'email name:&lt;tjreedy': 0.16; 'raised.': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'subject:raised': 0.16; 'traceback.': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'logging': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'needed.': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'lines': 0.31; 'exceptions': 0.31; 'extract': 0.31; 'origin': 0.31; 'raised': 0.31; 'class': 0.32; 'url:python': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'doing': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'pm,': 0.38; 'expect': 0.39; 'url:mail': 0.40; 'from:charset:utf-8': 0.61; 'information': 0.63; '30,': 0.65; 'yes': 0.68
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=NJQuQDNJ01GxhEMdPu1/lADibF1uzI5Ml0NgRXg2dD0=; b=pj/4l44KGDc5PjmiOPX2njNj7TcGDuu5UHQwoOmVYWpT+x/ymXn6koCETPAOBFrTLk WaaZHVwZAEwVRfdH9QN7rYkY3hzzHFu1EWx8uMcgY96etBMyybEWwi708bF+Q3BAZh+L gscgodMlVw3xfgQj4CVIlte+Fs2iGAY4W90PYnhgCssqPSCHskdZTZrL/zkQl61frkTQ P8S8XrVnqZ2IYLV7jmmDrwKirVAkR/iXlFIU5agR6Xf6daenFv1tkUKgDbj4WaSmIw02 vv6ZqokraTEzYGan6tDBwADc8OLW+LPbjIiwEBqmp3QXheEuy4JvEbHDHFUM5VrCAMQr /syw==
X-Received by 10.202.51.132 with SMTP id z126mr4121357oiz.57.1414884158587; Sat, 01 Nov 2014 16:22:38 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CALyLaQJYpQX2Dq_9iUeR6y=P6U1kggw6V3e43qAy2HvFz1WACA@mail.gmail.com>
References <CALyLaQJxfX_3aeACPjjkfzOKx+5K=uG9_PJZVFAfiUbL2t=ekw@mail.gmail.com> <m2tuna$csq$2@ger.gmane.org> <CALyLaQJYpQX2Dq_9iUeR6y=P6U1kggw6V3e43qAy2HvFz1WACA@mail.gmail.com>
From Néstor Boscán <nestorjb@gmail.com>
Date Sat, 1 Nov 2014 18:52:18 -0430
Subject Re: When using a decorator exceptions raised reference the decorator not the function
To Terry Reedy <tjreedy@udel.edu>
Content-Type multipart/alternative; boundary=001a113cbf38abccd10506d4634c
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15401.1414884168.18130.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414884168 news.xs4all.nl 2909 [2001:888:2000:d::a6]:45530
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80109

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

So actually what I ended up doing was a function that will return the last
tb_next and this will always give me the reference to the py and line
number where the exception was raised.

Regards,

Néstor

On Thu, Oct 30, 2014 at 4:42 PM, Néstor Boscán <nestor.boscan@tcs.com.ve>
wrote:

> Thanks Terry
>
> Yes both lines where in the traceback using tb_next I got what I needed.
>
> Regards,
>
> Néstor
>
> On Thu, Oct 30, 2014 at 1:36 PM, Terry Reedy <tjreedy@udel.edu> wrote:
>
>> On 10/30/2014 8:33 AM, Néstor Boscán wrote:
>>
>>  I'm using Python 2.7 and I'm creating a class decorator that extract
>>> information from exceptions for logging purposes.
>>>
>>> Everytime an exception is raised from the original function and I
>>> extract the origin of the exception with sys.exc_info() I get a
>>> reference to the line in the decorator where the function is called, not
>>> the line of the original function where the exception was raised.
>>>
>>
>> I expect that both lines should be in the traceback.  Post an example
>> where you do not intercept the exception.
>>
>> --
>> Terry Jan Reedy
>>
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>

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


Thread

Re: When using a decorator exceptions raised reference the decorator not the function Néstor Boscán <nestorjb@gmail.com> - 2014-11-01 18:52 -0430

csiph-web