To my knowledge, it is not possible to catch exceptions inside a velocity template. Generally, there are two ways of dealing with such a situation:
- handle the exception in the application which uses the template, such as a servlet
- avoid throwing exceptions; instead, have the method always return a valid (default) value, or
null
if that is not possible
The velocity manual recommends to use the second option whenever possible.