---
id: "M:cAlgo.API.Robot.OnError(cAlgo.API.Error)"
kind: "method"
type: "T:cAlgo.API.Robot"
url: "https://help.ctrader.com/ctrader-algo/references/General/Robot/OnError/"
---

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

# Robot.OnError

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

## OnError(Error error)

Called if there is an error executing a trade operation.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
protected internal void OnError(Error error)
```

Python:

```python
api.OnError(error: Error) -> None
```

### Parameters

- `error` (`Error`, Python `Error`): Error description.

### Examples

C#:

```csharp
protected override void OnError(Error error)
{
    Print("Trade error: {0}", error.Code);
    if (error.Code == ErrorCode.NoMoney)
        Stop();
}
```

Python:

```python
def on_error(self, error):
    api.Print(f"Trade error: {error.Code}")
    if error.Code == ErrorCode.NoMoney:
        api.Stop()
```

