Exception Handling

Release 1.0 - ...

Exception handling in SXML is done using the try...catch metaphor. The error parameter can be used to trap and handle errors that occur during runtime.

Trapping exceptions in SXML

Smartsite SXML CopyCode image Copy Code
<se:region error="Error occured: {this.error.message()}">
  (...)
</se:region>

The following Viper methods can be used in the error parameter:

Untrappable exceptions

The following exceptions are not trapped during page processing:

  • ThreadAbortedException
  • StopProcessingException and all exceptions that derive from it, like SyntaxErrorException
  • XmlException

When in-line rendering other items using one of the embedding techniques like the embed macro however, exceptions are always wrapped in a SmartsiteRuntimeException. This way, you have control over the error that you want to raise when embedded items throw exceptions.

Throwing exceptions

You can throw exceptions yourself directly from SXML.

In the error parameter, you can use these instance Vipers:

  • This.error.throw()
  • This.error.innerexception.throw()

Also, you can throw new exceptions from any SXML code block, using the sys.throwexception() method.

Smartsite SXML CopyCode image Copy Code
<se:region>
  {sys.throwexception("SyntaxError", "Wrong syntax")}
</se:region>