1.6.1 Basic Usage

The easiest way of catching and handline errors is to use try:.. except:.. block around all your code as shown below:

try:
    raise Exception('This error will be caught and nicely displayed')
except:
    print "An error occured"

If you want more control than this you can use the web.error module is as follows:

import web.error
web.error.handle()

raise Exception('This error will be caught and nicely displayed')

This will produce a full HTML page giving the tracback of the error.

Python allows you to put both lines of code on one line to make things look neater if you use a ; so in some of the following samples the error handling initialising will look like this:

import web.error; web.error.handle()

See About this document... for information on suggesting changes.