librelist archives

« back to archive

How to handle the application error?

How to handle the application error?

From:
刘一新
Date:
2011-11-24 @ 11:31
Hi,

First, a quick question. In documentaion, the following code

@app.errorhandler(404)def page_not_found(e):
    return render_template('404.html'), 404

is used to demonstrate the usage of errorhandler. I wonder what is the
role of 'e' here in page_not_found(e)? Can I pass this e as an error
message when rendering 404.html? Further, this function is invoked
when abort(404) is called, so where is 'e' comes from?

The other question is what is the best practice to handle the
application error other than the 404, 403, etc.

Thanks in advance.

-- 
*Yi-Xin Liu, PHD*
*Department of Macromolecular Science*
*Fudan University*
*Room 415, Yuejing Building *
*Handan Rd. 220, **Shanghai, China*
*Tel +86-021-65642863*
*Mobile +86-13916819745*
http://www.mendeley.com/profiles/yi-xin-liu/

Re: [flask] How to handle the application error?

From:
Simon Sapin
Date:
2011-11-24 @ 11:37
Le 24/11/2011 12:31, 刘一新 a écrit :
>   I wonder what is the role of 'e' here in page_not_found(e)? Can I pass
this e as an error message when rendering 404.html? Further, this function
is invoked when abort(404) is called, so where is 'e' comes from?

Hi,

abort(404) is just a shortcut to raise a NotFound exception. Error 
handlers are called when such an exception is caught. "e" is the 
exception object. I guess it is not useful for 404 but could be for 
other exceptions.

Regards,
-- 
Simon Sapin