Skip to content

Exception and Assertion

Purpose

Unless caught in your Groovy script, all exceptions thrown will be caught by the Platform 6 runtime and generate an ERROR log message, for example:

* Runtime error in Groovy script at line: 1 *: com.amalto.b2box.core.impl.groovy.ast.sandbox.SandboxException

In addition, this error message along with details of the underlying cause of the exception are thrown back to the caller.

Examples

Exceptions can be thrown from a Groovy script in the usual way.

throw new B2boxException("Found text when a number was expected")

Assertions are a better choice than Exceptions when a script is being used to validate content and return specific error messages to a caller. For example:

assert 1 == 2 : "One does not equal two"

Assert statements can be added to a script and if an assertion evaluates to false, the specific reason message is used as the exception message thrown back to the caller. If the reason message is omitted (as it’s optional), details of the failed assertion are returned instead.