<:try:> <:except:> [ <:else:> ] <:/try:>
or
<:try:> <:except [exc]:> [ <:except [exc]:> ] [ <:except:> ] [ <:else:> ] <:/try:>
or
<:try:> <:finally:> <:/try:>
This tag executes everything inside of it up until it first sees an <:except:> or <:finally:> tag. If an exception (error) occurs during that execution, this tag will then take one of the following actions:
If you have an <:else:> tag after all of your <:except:> tags, the stuff after <:else:> will be executed if no exception has occurred.
If you wish to specify particular exceptions in an <:except:> tag, use a backticked expression with the exception object. If you want to specify more than one exception for an <:except:> tag, specify them as a tuple expression.
Example:
<:try:> <:call `something_which_will_blow_up()`:> <:except `KeyError`:> We got a KeyError. <:except `(TypeError, ValueError)`:> We got a TypeError or ValueError. <:except:> We got some other error. But I know it wasn't a KeyError, TypeError, or ValueError! <:else:> Hey, no error!!!! <:/try:>
All of this behavior is identical to the way that try:, except: and else: work in regular Python. Read the Python documentation about exceptions for more info.
Note the last way to use the <:try:> tag: with a <:finally:> tag. The tags behave the same way as Python's try: and finally: statements.
CAVEAT PROGRAMMER: beware of the <:except:> tag with no arguments, as you may catch the document timeout exception (requestHandler.requestHandler.DocumentTimeout). If you catch it and ignore it, your document will never time out. Moral of the story, either:
FLASH! As of SkunkWeb 3.2.3, the document timeout exception will be reraised every second after a timeout occurs, so while you still need to be careful (say you have an operation that times out, wrapped in a try: block with a catchall except: in a while loop), you don't have to be quite as careful.