Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.python

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2012, 11:51 PM
Chris Angelico
Guest
 
Posts: n/a
Default Re: exception problem

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
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 06-25-2012, 07:49 AM
Steven D'Aprano
Guest
 
Posts: n/a
Default 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
Reply With Quote
  #3 (permalink)  
Old 06-25-2012, 08:08 AM
Chris Angelico
Guest
 
Posts: n/a
Default Re: exception problem

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
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 06:34 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.