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


Groups > comp.lang.python > #24407 > unrolled thread

Re: exception problem

Started byChris Angelico <rosuav@gmail.com>
First post2012-06-25 09:51 +1000
Last post2012-06-25 18:08 +1000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: exception problem Chris Angelico <rosuav@gmail.com> - 2012-06-25 09:51 +1000
    Re: exception problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-06-25 07:49 +0000
      Re: exception problem Chris Angelico <rosuav@gmail.com> - 2012-06-25 18:08 +1000

#24407 — Re: exception problem

FromChris Angelico <rosuav@gmail.com>
Date2012-06-25 09:51 +1000
SubjectRe: exception problem
Message-ID<mailman.1467.1340581879.4697.python-list@python.org>
On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson
<charleshixsn@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

[toc] | [next] | [standalone]


#24420

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-06-25 07:49 +0000
Message-ID<4fe8181e$0$29866$c3e8da3$5496439d@news.astraweb.com>
In reply to#24407
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

[toc] | [prev] | [next] | [standalone]


#24421

FromChris Angelico <rosuav@gmail.com>
Date2012-06-25 18:08 +1000
Message-ID<mailman.1479.1340611690.4697.python-list@python.org>
In reply to#24420
On Mon, Jun 25, 2012 at 5:49 PM, Steven D'Aprano
<steve+comp.lang.python@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web