Event Handling

Exception Events

Exception events are generated by FM-Classic whenever an unusual event occurs when a template is processed. For instance, if a TemplateModelException is thrown by a TemplateModel, an exception event will be propagated up to the current TemplateEventAdapter.

FM-Classic exception events are encapsulated in the TemplateExceptionEvent class. Objects of this class provide information about the exception that occurred, whereabouts in the code the exception occurred, and the severity of the exception. For convenience, TemplateExceptionEvents also contain the current Writer, so that exception messages can be sent directly to the template output stream.

TemplateExceptionListeners are notified of TemplateExceptionEvents whenever they are generated by FM-Classic at processing time. TemplateExceptionListeners are registered with a TemplateEventAdapter to indicate that they should receive these notifications.

FM-Classic comes with two implementations of TemplateExceptionListener: HtmlExceptionListener, which performs the standard output of FM-Classic exceptions into the template output stream, in the form of an HTML comment, and Log4jExceptionListener, which adapts FM-Classic exception events into Log4j logging messages. See the JavaDoc for more details of these implementations.