Try / Catch / Finally / End Try

A traditional way to check for hard errors and enable those errors to error softly.

Description:

One general use of the Try/Catch/Finally blocks is for when dynamic content is displayed depending a URL parameter. If the URL parameter provides an invalid value, we would like the page to display a soft error letting the user know that the parameter provided is invalid. Otherwise, Moxie will try to use the provided parameter to perform a database task and will likely return with a hard error.

Use the Try block for a test condition, if an error is returned from our Moxie Server, then the Catch block will be triggered. If the Try block's test condition does not cause an error, then the Catch block will not be triggered. Additionally, the Finally block will always run regardless of whether the Try block's condition caused an error or not.

Note: You can have multiple tests inside your Try block, however, if any of the tests trigger an error, the remaining tests will not be triggered and the Catch block will fire immediately upon first error.

Example:

1. invalid Try Test (catch block will run)

Try
    LoadRecord "MemTab.Person", "FakeAlias"
Catch
    HtmlAlert "There is no user for this alias."
Finally
    Html "This always runs!"
End Try

2. Valid Try Test (catch does not run)

Try
    LoadRecord "MemTab.Person", ($SessionUser)
Catch
    HtmlAlert "There is no user for this alias."
Finally
    Html "This always runs!"
End Try