except clause appears to be being skipped?

AWasilenko at gmail.com AWasilenko at gmail.com
Fri Mar 23 23:11:35 EDT 2007


On Mar 23, 10:29 pm, "John Machin" <sjmac... at lexicon.net> wrote:
> It *is* "pulling up the 404 function", which *is* returning your error
> page. However all your except clause does is "self.err404(dex)" -- you
> ignore the return value, and fall out of the except clause with
> textfile undefined, with the expected consequences.

Humm I dident think had to put return when I called the 404 becuase
the def has a return on the end of that, but now that I think about it
more it makes sence.



>
> I'm not at all familiar with cherrypy, but you probably need to do
> either:
>     errpage = self.err404(dex)
>     dosomethingwith(errpage, dex)
>     return
> or simply:
>     return "404 page title", self.err404(dex)
> [Actually it would be better style if the err404 method returned a
> tuple of (pagetitle, pagebody), then your except clause contains
> only:
>     return self.err404(dex)

Both of you're suggestions worked, Change it to return the tuple.




>
> The main point being to return instead of falling through the bottom
> of the except clause. BTW, you should not use a bare except. Be a
> little more specific, like except IOError:

Suggestion implemented, I figured you could be more specific with
exceptions but I must have glazed over that in my book when I read
about it.




> Looking at the cherrypy docs would seem indicated.
Since I'm a noobie python'r (or programmer for that matter) most if
not all of my mistkaes are with python and the syntax, there is not
much to screw up with Cherrypy itself, but I'm sure I will find a way
to screw it up later :)

> AFAIK there was a
> v1 and a v2 with different naming conventions and there's now a v3 --
> do ensure that you mention which version you are using if you need to
> come back with more questions.
>
> HTH,
> John

Naming conventions eh?  I guess I'm following conventions so far, I
havent ran into that problem yet (Knock Knock)

Thanks for you're help John, people like you make these newsgroups are
an invaluable resource :)




More information about the Python-list mailing list