API / Apache FreeMarker Interview questions
What is the difference between TemplateException and ParseException?
The two errors occur at different stages of a template's lifecycle.
| Aspect | ParseException | TemplateException |
| When thrown | While Configuration.getTemplate() parses the .ftl source | While Template.process() evaluates the parsed template against real data |
| Typical cause | Invalid FTL syntax - unclosed tags, bad expressions | Missing variable, wrong type used with a built-in, method-call failure |
| Depends on data? | No - purely a syntax problem in the source text | Yes - the same template can succeed or fail depending on what data it receives |
| Fix location | Edit the template file itself | Fix the data model or guard the expression with ?? / ! |
In short: a ParseException means the template could not even be compiled; a TemplateException means it compiled fine but failed while actually running against a specific data model.
More Related questions...