Throw Error
Purpose
To throw an informative error when a certain condition is met.
This JFunction can be used to throw informative errors when certain unwanted conditions are met in the model or input data. By checking for such conditions and then deliberately throwing an informative error, the model is prevented from moving forward and experiencing uncertain or unwanted effects downstream.
Type Name
‘throw_error’
Definition Syntax
The definition syntax is similar to that of an Equality, but with an additional element to specify the error details. The building blocks are:
[equality] ~ [error message to show]
thus:
[‘number’/‘text’ or ‘n’/‘t’] : [variable_name] [operator] [comparewith] : [case sensitive?] ~ [error message]
where:
- [‘number’/‘text’ or ‘n’/‘t’] specifies whether the values being compared are numeric values or text.
- [variable_name] is the name of a variable or function key in the parameter list.
- [operator] is one of the allowed operators (see below for operator codes that are allowed).
- [comparewith] is a number or text value with which the variable will be compared, or the name of a variable or function key to compare with.
- [error message] is an informative error message to explain the problem
Example
To throw an error if parameter ‘para_adt’ is below 10, you will use the following setup code:
n: para_adt < 50 ~ ADT is less than 50, how can this be?
With this setup code, if the model encounters a condition where parameter ‘para_adt’ has a value of less than 50, then Cassandra will throw an error with the message: ‘ADT is less than 50, how can this be?’
In the Cassandra model run log, this error will appear as follows: