---
title: "try — Error handling"
description: "iXML command try: Error handling."
canonical_url: "https://www.zeyos.com/ixml/ref/try"
markdown_url: "https://www.zeyos.com/ai/guide/ixml/ref/try.md"
section: "ixml-reference"
authority: "reference"
language: "en"
source_repository: "https://cloud.zeyos.com/__doc/ixmldoc.xml"
source_sha256: "a23f04e6a98628ca3c273c3b8dd2c33c034cfda3e0f00478d8793074fd2f70dd"
---

# try — Error handling

The TRY construct is a control flow structure that handles the occurrence of errors, warnings, exceptions and other special conditions that change the normal control flow.

An error can be thrown and caught. Code may be surrounded by a TRY statement, to facilitate the catching of potential errors. If an error is thrown or otherwise triggered within a TRY statement, the control flow continues with the execution of the embedded CATCH statement with the error message assigned to 'var'. In case no error occurs, the control flow continues with the execution of the embedded ELSE statement instead. Eventually the control flow always continues with the execution of the embedded FINALLY statement wheter an error occurred or not.

### Attributes
- (none)

### Children
- catch (occurrence: single) — Error triggered execution
- else (occurrence: single) — Elsewise execution
- finally (occurrence: single) — Final execution

### Parents
- (not restricted in the reference)

### Result
- (none documented)

### Examples

```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! -->
```

```xml
<try>
	<set var="name">iXML</set>

	<catch>
		<set var="output">My name is unknown!</set>
	</catch>

	<else>
		<set var="output">My name is $name!</set>
	</else>

	<finally>
		<output>$output</output>
	</finally>
</try>

<!-- My name is iXML! -->
```
