Deutsch English Français Italiano |
<method-20240504145813@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Re: how to discover what values produced an exception? Date: 4 May 2024 14:15:02 GMT Organization: Stefan Ram Lines: 36 Expires: 1 Feb 2025 11:59:58 GMT Message-ID: <method-20240504145813@ram.dialup.fu-berlin.de> References: <8734qz9ey0.fsf@tudado.org> <exceptions-20240503152349@ram.dialup.fu-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de T6bbYBZcrNwm6YyY2mwMmAupunLO1SYSATsfdPjVyXg3BG Cancel-Lock: sha1:AAvIF3dx8ULUakAv0u9By7F6aUs= sha256:CLylVsDbg2ljv0DpcyLkVDds7DV2yF+9R0Me2JQoJO4= X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 2576 ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted: >Sometimes you really need those values. If they're values of global >names, you can kind of get them in the IDLE shell up to a point. The way I see it, the issue here isn't just on Python, the language - it's also on us, the coders! I mean, when I define my own function, I can roll with something like: def function( value ): if value > 0: return log( value ) else: raise ZeroDivisionError( 'domain error' ) print( function( -1 )) . Or I can go with something like this: def function( value ): if value > 0: return log( value ) else: message = 'domain error: ' message += '\nThe argument value was: '+ repr( value ) + '.' message += '\nbut a value > 0 was expected.' raise ZeroDivisionError( message ) print( function( -1 )) . And you know what? The second option's gonna give you this output: ZeroDivisionError: math domain error: The argument value was: -1. but a value > 0 was expected. .