Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
exception problem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  24 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Charles Hixson  
View profile  
 More options Jun 24 2012, 6:26 pm
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Sun, 24 Jun 2012 15:26:59 -0700
Local: Sun, Jun 24 2012 6:26 pm
Subject: exception problem
The code:
                 print    ("pre-chunkLine")
                 chunks    =    []
                 try:
                     chunks    =    self.chunkLine (l)
                 except:
                     print    ("caught exception")
                     print (sys.exc_info()[:2])
                 finally:
                     print ("at finally")
                 print ("chunks =")
                 print (repr(chunks), ".", end = ":")
produces this result:
   . . ., by
pre-chunkLine
caught exception
at finally
path  3...

Any suggestions as to what's wrong with the code?
FWIW, chunkLine begins:
     def chunkLine (self, line):
         print    ("chunkLine: ")
         print ("line = ", line)
         if    line == None:
             return    []
         assert    (isinstance (line, str) )

--
Charles Hixson


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Hixson  
View profile  
 More options Jun 24 2012, 6:30 pm
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Sun, 24 Jun 2012 15:30:09 -0700
Local: Sun, Jun 24 2012 6:30 pm
Subject: Re: exception problem
Sorry, I left out:
er$ python3 --version
Python 3.2.3rc1

On 06/24/2012 03:26 PM, Charles Hixson wrote:

--
Charles Hixson

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Jun 24 2012, 6:36 pm
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Mon, 25 Jun 2012 08:36:11 +1000
Local: Sun, Jun 24 2012 6:36 pm
Subject: Re: exception problem
On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson

<charleshi...@earthlink.net> wrote:
> The code:
>                finally:
>                    print ("at finally")
>                print ("chunks =")
> produces this result:
> path  3...

Can you state more clearly the problem, please? I'm seeing output that
can't have come from the code posted (for instance, immediately after
the "at finally", I'm expecting to see the "chunks =" line), and I'm
not seeing any exception information, so I can't even hazard a guess
as to what's throwing the exception.

Presumably these are two methods in the same class, since you're
calling it as "self.chunkLine", but beyond that, it's hard to know.
Take off the try/except and let your exception go to console, that's
usually the easiest thing to deal with.

Chris Angelico


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Jun 24 2012, 6:43 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Sun, 24 Jun 2012 23:43:56 +0100
Local: Sun, Jun 24 2012 6:43 pm
Subject: Re: exception problem
On 24/06/2012 23:26, Charles Hixson wrote:

Don't use a bare "except"; it'll catch _any__exception. Catch only what
you expect.

For all I know, it could be that the name "l" doesn't exist.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Jun 24 2012, 6:45 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Sun, 24 Jun 2012 18:45:45 -0400
Local: Sun, Jun 24 2012 6:45 pm
Subject: Re: exception problem
On 06/24/2012 06:30 PM, Charles Hixson wrote:

On your except line, you forgot both the type of exception you're
expecting and the variable to receive its value.  So you're masking all
errors, including a name error finding chunkline().

You don't include enough code to make the fragment executable, so I'd
have to just guess.  I'm guessing that chunkline() is not defined in the
same class as that first method, whatever it was called.

If this were my problem, probably first thing I'd try is to remove the
try and catch, and see what it shows.  Bare exceptions are the bane of
programming;  Using it is like trying to learn to drive while blindfolded.

--

DaveA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Jun 24 2012, 6:59 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Sun, 24 Jun 2012 23:59:18 +0100
Local: Sun, Jun 24 2012 6:59 pm
Subject: Re: exception problem
On 24/06/2012 23:36, Chris Angelico wrote:
> On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson
> <charleshi...@earthlink.net> wrote:
>> The code:
>>                finally:
>>                    print ("at finally")
>>                print ("chunks =")
>> produces this result:
>> path  3...

> Can you state more clearly the problem, please? I'm seeing output that
> can't have come from the code posted (for instance, immediately after
> the "at finally", I'm expecting to see the "chunks =" line), and I'm
> not seeing any exception information, so I can't even hazard a guess
> as to what's throwing the exception.

I'd expect the output of:

print (sys.exc_info()[:2])

between these two lines:

caught exception
at finally

That suggests to me that "sys" hasn't been imported and that's there's
another exception somewhere that we're not seeing.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Hixson  
View profile  
 More options Jun 24 2012, 7:16 pm
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Sun, 24 Jun 2012 16:16:25 -0700
Local: Sun, Jun 24 2012 7:16 pm
Subject: Re: exception problem
On 06/24/2012 03:43 PM, MRAB wrote:

But what I wanted was to catch any exception.  A problem was happening
and I had no clue as to what it was.  (It turned out to be "self is not
defined".  A silly mistake, but a real one.)

The odd thing was that if I ran it without the try block, I didn't get
any exceptions at all.  (Which I clearly should have, except that since
self wasn't defined, I'd usually expect the interpreter to detect the
error before trying to execute the code.)

--
Charles Hixson


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Jun 24 2012, 7:51 pm
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Mon, 25 Jun 2012 09:51:15 +1000
Local: Sun, Jun 24 2012 7:51 pm
Subject: Re: exception problem
On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson

<charleshi...@earthlink.net> wrote:
> But what I wanted was to catch any exception.  A problem was happening and I
> had no clue as to what it was.  (It turned out to be "self is not defined".
>  A silly mistake, but a real one.)

> The odd thing was that if I ran it without the try block, I didn't get any
> exceptions at all.  (Which I clearly should have, except that since self
> wasn't defined, I'd usually expect the interpreter to detect the error
> before trying to execute the code.)

Python, not having any concept of declared variables, can't detect
such errors prior to execution. The error isn't like in C where you're
trying to use a variable that's not declared; the error is that, at
run time, there's no global with the name "self". That's why it's an
exception, not a compile-time error.

But the real question is: Why do you get no exception traceback if you
remove the try/except? Is something else swallowing everything thrown?
This is something that you will need to solve. (And it's a pretty
annoying issue. We had the same thing here at work, though in
Javascript not Python; a framework was swallowing exceptions, so all
sorts of work was being done blindfolded. Legacy code is not fun. Life
got a lot easier for us last Friday when I found and excised the
offending try/catch.) Hunt around and see if exceptions are getting
logged someplace other than your console - not uncommon if, for
instance, you're running in a web server. This is not going to be the
only time when you get an exception that could be massively helpful.

Mind you, I think every programmer should spend some time debugging
blind. It gives you such an appreciation for interactive debuggers.
Plus, it's an exercise in making your problems reproducible, if you
have to start your program over every time you add some more
information to it :)

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Jun 24 2012, 9:02 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Sun, 24 Jun 2012 21:02:29 -0400
Local: Sun, Jun 24 2012 9:02 pm
Subject: Re: exception problem
On 06/24/2012 07:16 PM, Charles Hixson wrote:

> On 06/24/2012 03:43 PM, MRAB wrote:
>> On 24/06/2012 23:26, Charles Hixson wrote:
>>> <SNIP>

>> Don't use a bare "except"; it'll catch _any__exception. Catch only what
>> you expect.

>> For all I know, it could be that the name "l" doesn't exist.
> But what I wanted was to catch any exception.  A problem was happening
> and I had no clue as to what it was.  (It turned out to be "self is
> not defined".  A silly mistake, but a real one.)

If you don't get anything else out of this thread, get this point.  A
bare except is exactly the opposite of what you want to debug an
exception.  It swallows all the information that python would have
displayed for you.

Four or five of us have made the same point, so please listen.

--

DaveA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Hixson  
View profile  
 More options Jun 25 2012, 1:27 am
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Sun, 24 Jun 2012 22:27:40 -0700
Local: Mon, Jun 25 2012 1:27 am
Subject: Re: exception problem
On 06/24/2012 03:43 PM, Charles Hixson wrote:

The documentation section covering the except statement could stand to
be a *LOT* clearer.   I read the sections on the except statement and
exception handlers several times and couldn't figure out was the "as"
argument of the except statement was for.  "Target" doesn't communicate
much to me.  The one I finally used as indicated above was modified from
some code that I found through Google.  I still don't really know what
"as" means, except that if you use it, and you print out the "target",
you'll get some kind of informative message.  (The one that I got said
"self was not defined" .. that's a paraphrase.  I can't remember the
precise wording.)  And that interpretation is based on what the result
was, not on anything said in the documentation.

IIRC, the Python2 documentation used code examples to indicate what was
the right way to write an exception handler.  I realize that Python3 is
much different, but that approach was a very good one.


--
Charles Hixson

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shambhu Rajak  
View profile  
 More options Jun 25 2012, 1:19 am
Newsgroups: comp.lang.python
From: Shambhu Rajak <Shambhu.Ra...@kpitcummins.com>
Date: Mon, 25 Jun 2012 05:19:17 +0000
Local: Mon, Jun 25 2012 1:19 am
Subject: RE: exception problem
If you are not sure about the Exception, You can adopt a generic way of handling exception.

try:
....
except Exception,e:
        print str(e)

-Shambhu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Berg  
View profile  
 More options Jun 25 2012, 2:23 am
Newsgroups: comp.lang.python
From: Andrew Berg <bahamutzero8...@gmail.com>
Date: Mon, 25 Jun 2012 01:23:52 -0500
Local: Mon, Jun 25 2012 2:23 am
Subject: Re: exception problem
On 6/25/2012 12:27 AM, Charles Hixson wrote:
> The documentation section covering the except statement could stand to
> be a *LOT* clearer.   I read the sections on the except statement and
> exception handlers several times and couldn't figure out was the "as"
> argument of the except statement was for.

I agree that the tutorial doesn't explain the use of "as" very well, but
it does cover that a bare except is not normally good to use:
"The last except clause may omit the exception name(s), to serve as a
wildcard. Use this with extreme caution, since it is easy to mask a real
programming error in this way!"

> I still don't really know what
> "as" means, except that if you use it, and you print out the "target",
> you'll get some kind of informative message.

"as" lets you refer to the exception object that was caught. I find this
useful mainly for exceptions that have attributes (most built-in
exceptions don't, but many user-defined exceptions do). A full traceback
is much more useful for debugging than what a simple print(exc) will give.
There are a few different ways to get traceback information without
letting the exception simply propagate and terminate the program. You
can get some simple information from sys.exc_info() (and you can feed
the traceback object to a function in the traceback module), or you can
log it with the logging.exception() function or the exception() method
of a Logger from the same module. I recommend using logging. However,
it's generally best to just let any unexpected exceptions propagate
unless the program absolutely must continue, especially when debugging.
--
CPython 3.3.0a4 | Windows NT 6.1.7601.17803

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Jun 25 2012, 3:40 am
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 25 Jun 2012 07:40:17 GMT
Local: Mon, Jun 25 2012 3:40 am
Subject: Re: exception problem

On Sun, 24 Jun 2012 18:45:45 -0400, Dave Angel wrote:
> Bare exceptions are the bane of
> programming;  Using it is like trying to learn to drive while
> blindfolded.

+1 QOTW

I really wish bare exceptions were removed from Python 3. There's no
point to try...except any longer, and it's just an attractive nuisance to
beginners.

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Jun 25 2012, 3:48 am
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 25 Jun 2012 07:48:35 GMT
Local: Mon, Jun 25 2012 3:48 am
Subject: Re: exception problem

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...

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Jun 25 2012, 3:49 am
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 25 Jun 2012 07:49:50 GMT
Local: Mon, Jun 25 2012 3:49 am
Subject: Re: exception problem

On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote:
> Mind you, I think every programmer should spend some time debugging
> blind.

You're a cruel, cruel man.

I suppose next you're going to say that every programmer should spend
some time programming using Notepad as their only editor.

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Jun 25 2012, 4:08 am
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Mon, 25 Jun 2012 18:08:07 +1000
Local: Mon, Jun 25 2012 4:08 am
Subject: Re: exception problem
On Mon, Jun 25, 2012 at 5:49 PM, Steven D'Aprano

<steve+comp.lang.pyt...@pearwood.info> wrote:
> On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote:

>> Mind you, I think every programmer should spend some time debugging
>> blind.

> You're a cruel, cruel man.

> I suppose next you're going to say that every programmer should spend
> some time programming using Notepad as their only editor.

No no, that's just *too* nasty.

But there are times now and then when, perhaps, you're working
remotely, and you have to figure out what's wrong without exception
tracebacks. Sure, 95% of programmers will never be in that situation,
but it's a good skill to have. And when that disaster _does_ strike
and you're stuck with just a file uploader and a crashing script,
you'll look awesome for being able to fix it in five minutes flat :)

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Hixson  
View profile  
 More options Jun 25 2012, 11:14 am
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Mon, 25 Jun 2012 08:14:04 -0700
Local: Mon, Jun 25 2012 11:14 am
Subject: Re: exception problem
On 06/24/2012 11:23 PM, Andrew Berg wrote:

I read that that would happen, but "  print (sys.exc_info()[:2]) "
didn't even yield a blank line.  It must have executed, because the
print statement on the line before it executed, and there wasn't a loop
or a jump (and also execution continued "normally" [the code still has
bugs] afterward even if the finally isn't included).

--
Charles Hixson


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Jun 25 2012, 11:22 am
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Tue, 26 Jun 2012 01:22:08 +1000
Local: Mon, Jun 25 2012 11:22 am
Subject: Re: exception problem
On Tue, Jun 26, 2012 at 1:14 AM, Charles Hixson

<charleshi...@earthlink.net> wrote:
> I read that that would happen, but "  print (sys.exc_info()[:2]) " didn't
> even yield a blank line.  It must have executed, because the print statement
> on the line before it executed, and there wasn't a loop or a jump (and also
> execution continued "normally" [the code still has bugs] afterward even if
> the finally isn't included).

Unless it threw an exception, such as NameError if you haven't
imported sys. In that case, execution will continue through the
'finally' clause and then raise the exception (at least, I think
that's how it goes - raising exceptions in exception handlers is not
something I've made a study of).

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Jun 26 2012, 5:36 pm
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Wed, 27 Jun 2012 07:36:09 +1000
Local: Tues, Jun 26 2012 5:36 pm
Subject: Re: exception problem
(You posted privately to me again; I hope you don't mind my responding
on-list as this appears to have been merely oversight.)

On Wed, Jun 27, 2012 at 5:25 AM, Charles Hixson

<charleshi...@earthlink.net> wrote:
> Only thing is, this whole mess started when I was trying to trace down and
> expected error.  (Which turned out to be "self.chunkLine(..." where self
> wasn't defined.)  It was running without ANY error being displayed.  Though
> as I look an outer loop is inclosed in a try:except:finally:  It still has
> an unlabelled except, because I don't remember what exception is thrown when
> a file reads an unintelligible character  (i.e., it isn't really a utf-8
> file).  Currently I've fixed all the files so that they're either utf-8 or
> just ASCII, so currently it isn't getting triggered, but it's still there.
>  So that's probably the explanation.  I think I'll fix that now.  (I can, I
> guess, assume that any exception will be caught by except BasicException:)

That's the problem, your blanket try/except. Don't do it! It blinds
you. Same goes for catching Exception or BaseException. Catch what you
really need to catch, and reserve catch-all statements for special
cases where you don't have access to the console.

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRAB  
View profile  
 More options Jun 26 2012, 6:30 pm
Newsgroups: comp.lang.python
From: MRAB <pyt...@mrabarnett.plus.com>
Date: Tue, 26 Jun 2012 23:30:46 +0100
Local: Tues, Jun 26 2012 6:30 pm
Subject: Re: exception problem
On 26/06/2012 22:36, Chris Angelico wrote:

If you can't remember what exception is raised, just try raising it
deliberately.

Python _can_ be used interactively, after all. Even a short script to
test it won't take you very long!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Hixson  
View profile  
 More options Jun 27 2012, 8:13 pm
Newsgroups: comp.lang.python
From: Charles Hixson <charleshi...@earthlink.net>
Date: Wed, 27 Jun 2012 17:13:00 -0700
Subject: Re: exception problem
On 06/25/2012 12:48 AM, Steven D'Aprano wrote:

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
alex23  
View profile  
 More options Jun 27 2012, 8:36 pm
Newsgroups: comp.lang.python
From: alex23 <wuwe...@gmail.com>
Date: Wed, 27 Jun 2012 17:36:21 -0700 (PDT)
Local: Wed, Jun 27 2012 8:36 pm
Subject: Re: exception problem
On Jun 28, 10:13 am, Charles Hixson <charleshi...@earthlink.net>
wrote:

> On 06/25/2012 12:48 AM, Steven D'Aprano wrote:
> > "Catch any exception" is almost certainly the wrong thing to do, almost
> > always.
> 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.

I think you're still missing the point. If you _didn't_ have a bare
try/except, the exception _would have been raised_ and the exception
displayed.

You _don't_ need an exception handler for exceptions to occur, they
just occur. You _only_ need a handler when you want to, y'know, handle
them.

> 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 documentation doesn't expect you to write code to block error
reporting. If you had just removed the try/except, you would have seen
the problem right away.

> 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.

Can I suggest re-looking at the tutorial for errors & exceptions? I
really think you're making this a lot more difficult for yourself than
it needs to be.

http://docs.python.org/tutorial/errors.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Jun 27 2012, 11:44 pm
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 28 Jun 2012 03:44:43 GMT
Local: Wed, Jun 27 2012 11:44 pm
Subject: Re: exception problem

If you had simply NOT caught it, the full traceback would have been
printed automatically and you could have easily seen what exception was
being raised, the error message, and where it was being raised from.

This is exactly why you should not have used a bare except, or any except
at all, but just let the uncaught exception print on its own. When trying
to diagnose bugs, try...except is not your friend. Tracebacks are your
friend.

[...]

> 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.

If you have concrete examples of where you think the documentation could
be improved, please either raise an enhancement request or bug report:

http://bugs.python.org/

or at least raise them here (and hope somebody else raised the bug
report).

Otherwise, there's nothing we can do about vague complaints.

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ethan Furman  
View profile  
 More options Jun 28 2012, 8:52 am
Newsgroups: comp.lang.python
From: Ethan Furman <et...@stoneleaf.us>
Date: Thu, 28 Jun 2012 05:52:57 -0700
Local: Thurs, Jun 28 2012 8:52 am
Subject: Re: exception problem

Charles Hixson wrote:
> On 06/25/2012 12:48 AM, Steven D'Aprano wrote:
>> "Catch any exception" is almost certainly the wrong thing to do, almost
>> always.

> This time it was the right thing

No, it wasn't.  If you hadn't caught it, Python would have printed it
out for you, along with the full trace-back, giving you most if not all
the information you needed to track down the bug.

~Ethan~


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »