MTException 1.0

June 13, 2003 - updated February 8, 2006 (Download)

In MovableType, blog pages are generated from templates. Sometimes re-building a page may fail for various reasons at which time MovableType reports an error. The tags in this plugin allow you to handle errors that occur during the building stage of your pages. The tags are modeled after the try-catch error handling approach common to languages such as Java and C++. You would enclose the part of template where you want to handle errors into MTExceptionTry tags. If an error occurs while building the page, the MTExceptionTry simply returns an empty string, instead of causing an error. You can optionally specify an MTExceptionCatch block inside your MTExceptionTry block. If an error occurs, the contents of the catch block are displayed.

Templates are actually processed in two stages. At the first stage, the template is compiled into sections of text and tags. During this stage MovableType reports any syntax errors that are in your template, for example if you have an <MTEntries> tag without a corresponding </MTEntries> tag. After a template has been compiled, MovableType uses it to build files from entries in the database. During this stage of errors may be reported. For example, you might be using a tag outside of it’s context—such as using an MTCategoryLabel tag when you are not in a category template. Or the tag may fail for other reason—such as trying to MTInclude a module that doesn’t exist or trying or using MTGetVar for a variable that has not been set. Since this plugin gets used during the building stage, it cannot catch any syntax errors that you run during the compile stage.

Example: The following code displays the contents of the variable “x”. If the variable “x” has not been defined, an empty string is displayed (instead of an error):

<MTExceptionTry><MTVarGet name="x"></MTExceptionTry>

Example: The following code displays the contents of the module specified by the MTCategoryLabel. If the module doesn’t exist, the module “Category Default” is used instead:

<MTExceptionCatch><MTLoad module="Category Default"></MTExceptionCatch>
<MTLoadModule>Category <MTCategoryLabel></MTLoadModule>

  • MTExceptionTry
    Container tag that suppress any errors generated within it.
  • MTExceptionCatch
    Container tag—inside of an MTExceptionTry block—whose contents are displayed when an error occurs following this tag.
  • MTExceptionError
    Tag that can be used inside the MTExceptionCatch block to display the error string that caused the error.

    Example: Catch an error and display it in your page.

    The following error occurred: <MTExceptionError>
  • MTExceptionWarnings
    Container tag that contains all the warnings that were generated inside the MTExceptionTry block.
  • MTExceptionWarning
    Displays a single warning string when used inside the MTExceptionWarnings loop. When used outside of the loop, displays all warnings at once.
  • MTExceptionWarn
    Container tag that generates a warning. If used inside the try block, the warning can be later displayed using the MTExceptionWarning tags. If used outside the try block, the warning is displayed in the browser window.
  • MTExceptionThrow
    Container tag that generates an error. If used inside the try block, the error can be caught using the MTExceptionCatch tags. If used outside the try block, the error is displayed in the browser.
  • MTExceptionRethrow
    Tag that can be used inside the MTExceptionCatch block to re-generate the error.