REPORT_ERROR
Stops processing the template and report the specified error message.
Used inside conditions (such as IF
), REPORT_ERROR
let’s you prevent a template from being used with incorrect values.
Usage
Parameters
message |
(Required) The text of the error message to display |
Examples
More information
Just like any function, REPORT_ERROR
does nothing if is hidden/removed by an IF
, IFS
or @IF
…@ELSEIF
.
The REPORT_ERROR
function let’s you stop generating a document when a problem is detected by your commands.
Here are the two main situation where REPORT_ERROR
can help.
Limit when the template can be used
If your template is only meant to be used for adults, then REPORT_ERROR
can stop the processing
and provide a clear error message when the customer’s age is too low.
<# IF(age < 18, REPORT_ERROR("This template is for 18+ y/o customers")) #>
Report a missing case in the template
If your template lets you pick a teacher, for which it displays a short introduction in the generated document.
One way to do that would be to do consecutive @IF
…@ELSEIF
:
<# @IF(teacher_name = "Anna Logwatch") #>
Anna is great!
<# @ELSEIF(teacher_name = "Austin Wattage") #>
Austin likes movies!
<# @ENDIF #>
What would happen if teacher_name didn’t match any of the above choices? Well, right now, there would either
be no introduction, of if a @ELSE
was used for the final introduction, then that introduction would be used for anyone missing.
Both cases are not ideal.
This can happen because:
- We forgot a teacher when making the template
- There is a new teacher and we forgot to add his introduction to the template
- There was a typo in the name of a teacher
Here is the same example, but with a REPORT_ERROR
:
<# @IF(teacher_name = "Anna Logwatch") #>
Anna is great!
<# @ELSEIF(teacher_name = "Austin Wattage") #>
Austin likes movies!
<# @ELSE #>
<# REPORT_ERROR("No introduction for: " & teacher_name) #>
<# @ENDIF #>