> For the complete documentation index, see [llms.txt](https://docs.gentee.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gentee.org/syntax/error-handling.md).

# Error handling

### Try catch statement

By default, if an error was received at the time of the script execution, the script immediately finishes its work. If you want to avoid the termination of the script, you should use the **try** statement. If an error occurs during the execution of the code inside the *try* block, the control will pass to the **catch** block, which must be after **try**. After the *catch* keyword, it is necessary to specify the name of the variable of *error* type, which will contain information about the error. You can use \[special functions] (<https://gentee.github.io/stdlib/runtime#erriderror-err-int>) to get the identifier and error text. If you do not remove the error inside *catch* with **recover** or **retry**, it will be passed on and the script will finish its work.

```
TryStmt ="try" Block CatchStmt
CatchStmt = "catch" identifier Block
```

```
run  {
   try {
      myfunc()
      error(101, "Custom error")
   }
   catch err {
      if ErrID(err) != 101:  error( 102, "Error \{ErrText(err)} has occurred in myfunc()")
   } 
}
```

### Recover statement

The **recover** statement is used inside a **catch** block to remove the error. This command removes the error information, the script exits the current *catch* block and continues execution.

```
RecoverStmt = "recover"
```

```
run str {
   try : 10/0
   catch err :  recover
   return "ok"
} 
// ok
```

### Retry statement

The **retry** statement is used inside a **catch** block to restart **try**. This command removes the error information and the script re-executes the corresponding *try* block.

```
RetryStmt = "retry"
```

```
run {
   str fname
   try {
       fname = ReadString("Specify filename: ")
       Println("Beginning of the file: ", str(ReadFile(fname, 0, 50)))
    } catch err {
       Println("ERROR #\{ErrID(err)}: \{ErrText(err)}")
       retry
    }
}
```

##


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gentee.org/syntax/error-handling.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
