FreeMarker is a java based template engine for complex template processing.
This requires the library freemarker-2.3.16.jar to be in classpath.
The following example shows using attempt and recover directives in FreeMarker.
It is similar to try catch block in Java.
//Get template from classpath
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(AttemptRecoverTest.class, "/");
Template template = cfg.getTemplate("recover.ftl");
//Prepare data model
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("name", "Sriram");
dataModel.put("hobby", "Cricket");
//Merge template and data
StringWriter output = new StringWriter();
template.process(dataModel, output);