TemplateExceptionHandler (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.template, interface: TemplateExceptionHandler

Package freemarker.template

# Interface TemplateExceptionHandler

public interface TemplateExceptionHandler
Used for the `template_exception_handler` configuration setting.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static TemplateExceptionHandler`
  `DEBUG_HANDLER`
  `TemplateExceptionHandler` useful when you are developing non-HTML templates.
  `static TemplateExceptionHandler`
  `HTML_DEBUG_HANDLER`
  `TemplateExceptionHandler` useful when you are developing HTML templates.
  `static TemplateExceptionHandler`
  `IGNORE_HANDLER`
  `TemplateExceptionHandler` that simply skips the failing instructions, letting the template continue executing.
  `static TemplateExceptionHandler`
  `RETHROW_HANDLER`
  `TemplateExceptionHandler` that simply re-throws the exception; this should be used in most production systems.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `handleTemplateException​(TemplateException te, Environment env, Writer out)`
  Method called after a `TemplateException` was raised inside a template.

- ## Field Details

  - ### IGNORE_HANDLER

    static final TemplateExceptionHandler IGNORE_HANDLER
    `TemplateExceptionHandler` that simply skips the failing instructions, letting the template continue executing. It does nothing to handle the event. Note that the exception is still logged, as with all other `TemplateExceptionHandler`-s.

  - ### RETHROW_HANDLER

    static final TemplateExceptionHandler RETHROW_HANDLER
    `TemplateExceptionHandler` that simply re-throws the exception; this should be used in most production systems.

  - ### DEBUG_HANDLER

    static final TemplateExceptionHandler DEBUG_HANDLER
    `TemplateExceptionHandler` useful when you are developing non-HTML templates. This handler outputs the stack trace information to the client and then re-throws the exception.

  - ### HTML_DEBUG_HANDLER

    static final TemplateExceptionHandler HTML_DEBUG_HANDLER
    `TemplateExceptionHandler` useful when you are developing HTML templates. This handler outputs the stack trace information to the client, formatting it so that it will be usually well readable in the browser, and then re-throws the exception.

- ## Method Details

  - ### handleTemplateException

    void handleTemplateException​(TemplateException te, Environment env, Writer out) throws TemplateException
    Method called after a `TemplateException` was raised inside a template. The exception should be re-thrown unless you want to suppress the exception.

    Note that you can check with `Environment.isInAttemptBlock()` if you are inside a `#attempt` block, which then will handle this exception and roll back the output generated inside it.

    Note that `StopException`-s (raised by `#stop`) won't be captured here.

    Note that you shouldn't log the exception in this method unless you suppress it. If there's a concern that the exception might won't be logged after it bubbles up from `Template.process(Object, Writer)`, simply ensure that `Configurable.getLogTemplateExceptions()` is `true`.

    Parameters:
      `te` - The exception that occurred; don't forget to re-throw it unless you want to suppress it
      `env` - The runtime environment of the template
      `out` - This is where the output of the template is written
    Throws:
      `TemplateException`