If you use Cheetah, please support the project and register by clicking here:


10.1 #try ... #except ... #end try, #finally, and #assert

Cheetah's exception-handling directives are exact mirrors Python's exception-handling statements. See Python's documentation for details. The following Cheetah code demonstrates their use:

#try
  $mightFail()
#except
  It failed
#end try

#try
  #assert $x == $y
#except AssertionError
  They're not the same!
#end try

#try
  #raise ValueError
#except ValueError
  #pass
#end try


#try
  $mightFail()
#except ValueError
  Hey, it raised a ValueError!
#except NameMapper.NotFound
  Hey, it raised a NameMapper.NotFound!
#else
  It didn't raise anything!
#end try

#try
  $mightFail()
#finally
  $cleanup()
#end try

Like Python, #except and #finally cannot appear in the same try-block, but can appear in nested try-blocks.

If you use Cheetah, please support the project and register by clicking here: