---
title: Overbasic – Try .. Catch
description: "Correctly handling exceptions (possible errors during script execution) in order to avoid unexpected results, is fundamental in any programming language. In Overbasic you can handle exceptions using the TRY .. CATCH syntax. ### **Syntax** ``` Try Catch EndTry ``` The…"
url: "https://www.overcharts.com/en/helpcenter/docs/overbasic-try-catch/"
updated: "2022-12-02"
category: "Overbasic / Syntax & Keywords"
---

# Overbasic – Try .. Catch

Correctly handling exceptions (possible errors during script execution) in order to avoid unexpected results, is fundamental in any programming language. In Overbasic you can handle exceptions using the TRY .. CATCH syntax.

### **Syntax**

```
Try
    <code block>
Catch
    <code block>
EndTry
```

The **TRY** section contains the block of code to be executed.
The **CATCH** section allows you to define a block of code to be executed, if an error occurs in the TRY block.

In other words, if one of statements in the ***Try*** block throws an error, ***Try*** block execution ends immediately. Script execution continues with the ***Catch*** block.

### **Usage**

```
Dim result As Numeric = 0
Dim b As Numeric = 0

Try
    result = 100
    result = result / b 'This statement throws an error because b equals zero
    result = result + 1 'This statement will NOT be executed.
Catch
    result = 2
EndTry

result = result * 10

'The result is: 20
```

In the example, the execution of the Try block ends with the line **result = a / b** throwing a divide-by-zero error. Subsequent statements contained in the Try block will NOT be executed. Program execution will continue with the Catch block.
