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

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

# Plugin.OnException

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

## OnException(Exception exception)

Called on each unhandled exception.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

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):
    # Place your exception handling code here
    api.Print(exception.Message)
```

