Re: exception problem

Discussion in 'Python' started by Chris Angelico, Jun 25, 2012.

  1. On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson
    <> 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
    Chris Angelico, Jun 25, 2012
    #1
    1. Advertising

  2. 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
    Steven D'Aprano, Jun 25, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,529
  2. jeff
    Replies:
    3
    Views:
    1,689
    Scott
    Jun 26, 2003
  3. Kerri
    Replies:
    2
    Views:
    13,024
    Kevin Spencer
    Oct 27, 2003
  4. Ola
    Replies:
    0
    Views:
    532
  5. Selen
    Replies:
    0
    Views:
    2,685
    Selen
    May 28, 2004
Loading...

Share This Page