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


Groups > comp.lang.python > #24565

Re: exception problem

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <charleshixsn@earthlink.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'e.g.,': 0.07; 'exception.': 0.07; 'main()': 0.07; 'try:': 0.07; 'undefined': 0.07; 'variable,': 0.07; 'missed': 0.09; 'python': 0.09; 'err:': 0.09; 'exception:': 0.09; 'exceptions,': 0.09; 'gui': 0.11; 'assume': 0.11; 'do,': 0.15; 'file,': 0.15; 'for,': 0.16; 'message-id:@earthlink.net': 0.16; 'received:dsl.mindspring.com': 0.16; 'subject:exception': 0.16; 'suggesting': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'tend': 0.17; 'trying': 0.21; 'bit': 0.21; 'do.': 0.21; 'exceptions': 0.22; 'subject:problem': 0.22; 'programming': 0.23; "i've": 0.23; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'guess': 0.27; '(such': 0.27; 'went': 0.28; 'run': 0.28; '-0700,': 0.29; 'catching': 0.29; "d'aprano": 0.29; 'dialog': 0.29; 'steven': 0.29; 'wrap': 0.29; 'probably': 0.29; 'error': 0.30; '(and': 0.32; 'google,': 0.32; 'print': 0.32; 'comments': 0.33; "aren't": 0.33; 'problem': 0.33; 'to:addr :python-list': 0.33; 'skip:d 20': 0.34; 'wrong': 0.34; 'list': 0.35; 'expected': 0.35; 'something': 0.35; 'list.': 0.35; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'wanted': 0.36; 'totally': 0.36; "didn't": 0.36; 'method': 0.36; 'level': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'application': 0.40; 'skip:u 10': 0.60; 'first': 0.61; 'more': 0.63; 'show': 0.63; 'bothered': 0.65; 'lack': 0.71; 'examples.': 0.84; 'suspected': 0.84; 'thing,': 0.84; 'thrown,': 0.84; 'careful': 0.91
Date Wed, 27 Jun 2012 17:13:00 -0700
From Charles Hixson <charleshixsn@earthlink.net>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20120506 Icedove/3.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: exception problem
References <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <mailman.1466.1340579780.4697.python-list@python.org> <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1578.1340842369.4697.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1340842369 news.xs4all.nl 6915 [2001:888:2000:d::a6]:38448
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24565

Show key headers only | View raw


On 06/25/2012 12:48 AM, Steven D'Aprano wrote:
> On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote:
>
>    
>> But what I wanted was to catch any exception.
>>      
> Be careful of what you ask for, since you might get it.
>
> "Catch any exception" is almost certainly the wrong thing to do, almost
> always. The one good reason I've seen for a bare except is to wrap the
> top level of an application in order to redirect uncaught exceptions to
> something other than the console (such as a GUI error dialog box). And
> even then, you probably don't want to catch *all* exceptions, but only
> those that inherit from Exception:
>
> try:
>      main()  # run my application
> except Exception as err:
>      display_error_dialog(err)
>      # or log to a file, or something...
>
>
>
>    
This time it was the right thing, as I suspected that *SOME* exception 
was being thrown, but had no idea what one.  The problem was I didn't 
know how to print the result when I caught the exception.  This has 
since been cleared up, but first I found it on Google, and then I was 
told about it on the list.  The documentation left me totally ... well, 
not uninformed, but confused.  As I said it turned out to be a method 
call on an uninitialized variable, as I found out once I figured out how 
to list the result of catching the exception.  Which is what I expected 
the documentation to show me how to do.

The comments on the list have been vastly helpful, even if they still 
tend to assume that I know more than I do.  (And even if some of them 
seem to be a bit ... off.  E.g., suggesting that I generate the 
exception on purpose so I can find out what it is, when I started off 
with no idea as to WHAT the problem was.)

What really annoys me is the way the documentation has worsened since 
python 2.5, but if you know what it is trying to tell you, then I guess 
you aren't bothered by undefined terms and lack of examples.  I went 
away from programming in Python for a couple of years though, and I 
guess I missed the transition, or something.

-- 
Charles Hixson

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


Thread

Re: exception problem Charles Hixson <charleshixsn@earthlink.net> - 2012-06-24 16:16 -0700
  Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-25 07:48 +0000
    Re: exception problem Charles Hixson <charleshixsn@earthlink.net> - 2012-06-27 17:13 -0700
      Re: exception problem alex23 <wuwei23@gmail.com> - 2012-06-27 17:36 -0700
      Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-28 03:44 +0000
    Re: exception problem Ethan Furman <ethan@stoneleaf.us> - 2012-06-28 05:52 -0700

csiph-web