---
id: "M:cAlgo.API.Internals.Algo.OnException(System.Exception)"
kind: "method"
type: "T:cAlgo.API.Internals.Algo"
url: "https://help.ctrader.com/ctrader-algo/references/General/Algo/OnException/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# Algo.OnException

Member of [Algo](https://help.ctrader.com/ctrader-algo/references/General/Algo/index.md).

## OnException(Exception exception)

Called on each unhandled exception.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
protected internal void OnException(Exception exception)
```

Python:

```python
api.OnException(exception: Exception) -> None
```

### Parameters

- `exception` (`Exception`, Python `Exception`):

### Examples

C#:

```csharp
protected override void OnException(Exception exception)
{
    // Place your exception handling code here
    Print(exception.Message);
}
```

Python:

```python
def on_exception(self, exception):
    api.Print(exception.Message)
```

