# try

## try

## catch

try/catch statement.

### Syntax

* try, statements\_1, catch, statements\_2, end
* try, statements\_1, catch exception, statements\_2, end

### Description

**try** and **catch** statements are used for error handling and control in files.

**exception** is an **MException** object that allows you to identify the error.

The catch block assigns the current exception object to the variable in exception.

### Examples

try/catch in a script file

```matlab
try
error('an error')
catch
  disp('error catched')
end
```

try/catch in a script file

```matlab
try
error('an error')
catch ME
  ME
end
```

### See also

[run](../core/run), [execstr](../core/execstr), [MException](../error_manager/mexception).

### History

| Version | Description     |
| ------- | --------------- |
| 1.0.0   | initial version |

### Author

Allan CORNET
