Skip to main content

Throwing Errors

error — Throw error

The ERROR command explicitly throws an error, breaking out of the current control flow. The error propagates upward until it is caught by a <try>/<catch> block. If no <try>/<catch> block is present, the error terminates execution entirely.

The content of the <error> element becomes the error message string that is received by the <catch> block's var attribute. You can use variable substitution in the error message to include dynamic context information.

Full reference →

Syntax

XML
<error>Error message text with $variable substitution</error>

The content (type: string) is the error message.

When to use explicit errors

Use <error> to enforce business rules, validate preconditions, or signal application-level failures that the caller should handle. For expected conditions (like "record not found"), prefer <if> with <return> instead — <error> incurs exception-handling overhead and should be reserved for truly exceptional situations.

XML
<is var="payload.email" type="empty">
<error>Email address is required</error>
</is>

<if value1="$payload.amount" func="&lt;" value2="0">
<error>Amount must be non-negative, got: $payload.amount</error>
</if>

Example

XML
<try>
<set var="name">iXML</set>

<if value1="$name" func="=" value2="iXML">
<error>An error has occurred!</error>
</if>

<catch var="error">
<output>$error</output>
</catch>
</try>

<!-- An error has occurred! -->

See also


warning — Throw warning

The WARNING command throws a warning, which behaves similarly to an error: it breaks out of the current control flow and can be caught by a <try>/<catch> block. Warnings are a ZeyOS-specific mechanism for signaling non-critical issues that should be logged or reported but may not necessarily require the same handling as a full error.

Full reference →

Syntax

XML
<warning>Warning message text</warning>

The content (type: string) is the warning message.

note

Like errors, warnings are caught by <try>/<catch>. The <catch> block receives the warning message in its var attribute, just as it would for an error. There is no built-in way to distinguish between caught errors and caught warnings at the <catch> level — if you need to differentiate, use a convention in your message format or set a flag variable before throwing.

Example

XML
<warning>This is a warning!</warning>

See also

  • error — the standard error-throwing mechanism
  • Try / Catch — catching warnings