RaiseError

Instructs the expression engine to raise an error where one would not normally occur. This lets you design exact 'fail' conditions for your application that would not normally be picked up by an error handler.

Syntax

RaiseError( ErrorMessage );

Parameters

Parameter Name Type Description Optional? Default Value
ErrorMessage String The error message to return when the function triggers. No n/a

Output

If called on its own, the function will return the ErrorMessage string in the following format:

=ERROR: This is some error text

However, if this error is picked up by OnErrorJumpTo, the function won't return a value; instead, the value of ErrorMessage will be combined with the trace information assigned to the OnErrorJumpTo statement's ErrorVariableName parameter, if one has been specified.

Use Case

An online store's search facility is designed to return products matching a text string entered by a customer. In addition to exact matches, this feature is able to suggest approximate matches. This means that even if there are no products matching a particular search string, the site should still be able to suggest alternatives. The feature is designed so every query returns at least one result, otherwise something has gone wrong.

A query returning zero results is not an error in the broad sense, but in this case it should never happen, so if it somehow does the administrators want to raise a custom error. The error handler will then e-mail the administrators with details of the fault, and redirect the end user to a page that lets them know their query returned no results.

The relevant parts of the expression are included below. Comments have been used to represent areas of the expression that will perform some work, without writing out those areas in full.

OnErrorJumpTo(ErrorDetails):ZeroResultsException;

QueryResultsCount:= 0;

// The statements that process the end user's query go here. As part of this section, the number of results returned by the query will be assigned to the QueryResultsCount variable.;

If:(QueryResultsCount=0)
{
RaiseError("No results were returned.");
};

#ZeroResultsException:
{
// Error handling statements, including one to e-mail the site administrators and one to redirect the user to a different form, will go here.;
}