It doesn't work here (thank you though, add_processor() is
interesting).
err2() is not caught in yield_errors(), neither is err1().
I tried this (with some modification since 'yield' and 'return' don't
go together):
#!/usr/bin/env python
import web
web.internalerror=web.debugerror
urls=(
r'/(.*)', r'Index'
)
def yield_errors(handler):
try:
return handler()
except:
print 'unhandled error'
app=web.application(urls, globals())
app.add_processor(yield_errors)
class Index:
def GET(self, url):
#err1()
yield 'test'
err2()
if __name__=='__main__':
app.run()
On 15 déc, 17:06, andrei <[email protected]> wrote:
> you can do something like this for the whole app:
>
> def yeld_errors(handler):
> try:
> return handler()
> except Exception, e:
> yield str(e)
>
> app.add_processor(yeld_errors)
>
> On Dec 15, 11:41 am, je <[email protected]> wrote:
>
> > I'm using version 0.33.
>
> > try...except is what I am using right now, but with 20 or more classes
> > in this application, that's a lot of repetitive code to handle
> > unexpected errors.
>
> > Is there a way to "try...except" the whole app for unexpected errors,
> > like I would do in a regular python script with:
>
> > try:
> > main()
> > except:
> > display/log the error
>
> > ?
>
> > On 14 déc, 23:23, "W. Martin Borgert" <[email protected]> wrote:
>
> > > Quoting je <[email protected]>:
>
> > > > So, how, if possible, could I get the error displayed inside a
> > > > generator function using yield?
>
> > > Maybe sth. like this (if you want to have the error message shown
> > > in your web page):
>
> > > def GET(self):
> > > try:
> > > err1()
> > > yield ...
> > > err2()
> > > except Exception, e:
> > > yield str(e) # or similar
>
> > > Or if you want it printed on the console:
>
> > > except Exception, e:
> > > print str(e) # or add the stack trace from Python
>
> > > Just to be sure: You are using a recent web.py (> 0.3x) which
> > > does not use "print" anymore to return the HTML, right?
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.