> For the complete documentation index, see [llms.txt](https://yams.yassrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yams.yassrobotics.com/api-reference/c++-reference/exceptions.md).

# Exceptions

**Namespace:** `yams::exceptions` **Java equivalent:** [Java Exceptions](https://github.com/Yet-Another-Software-Suite/YAMS-Gitbook-API/tree/main/java/exceptions.md)

All YAMS C++ exceptions extend `yams::exceptions::YamsException`, which extends `std::runtime_error`.

***

## Base exception

```cpp
class YamsException : public std::runtime_error {
public:
    explicit YamsException(const std::string& message);
};
```

***

## Exception classes

| Class                                        | Thrown When                                                  |
| -------------------------------------------- | ------------------------------------------------------------ |
| `ArmConfigurationException`                  | Required `ArmConfig` fields are missing or invalid           |
| `ElevatorConfigurationException`             | Required `ElevatorConfig` fields are missing or invalid      |
| `PivotConfigurationException`                | Required `PivotConfig` fields are missing or invalid         |
| `SwerveDriveConfigurationException`          | Required swerve drive config fields are missing or invalid   |
| `SmartMotorControllerConfigurationException` | `SmartMotorControllerConfig` is invalid                      |
| `NoStagesGivenException`                     | `GearBox` or `Sprocket` constructed with an empty stage list |
| `InvalidStageGivenException`                 | A stage string is not in `"IN:OUT"` format                   |

***

## Constructor patterns

### Configuration exceptions

Most configuration exceptions follow this three-argument pattern:

```cpp
SomeConfigurationException(const std::string& issue,
                           const std::string& result,
                           const std::string& fix)
```

| Parameter | Description                                         |
| --------- | --------------------------------------------------- |
| `issue`   | Description of the invalid or missing configuration |
| `result`  | The runtime consequence of the misconfiguration     |
| `fix`     | Suggested corrective action                         |

### SwerveDriveConfigurationException

```cpp
explicit SwerveDriveConfigurationException(const std::string& message)
```

Takes a single message string rather than the three-argument pattern.

***

## Example

```cpp
try {
    positional::Arm arm{&armConfig, motor};
} catch (const exceptions::ArmConfigurationException& e) {
    fmt::print("Arm config error: {}\n", e.what());
} catch (const exceptions::YamsException& e) {
    fmt::print("YAMS error: {}\n", e.what());
}
```

{% hint style="info" %}
All YAMS exceptions are unchecked (derived from `std::runtime_error`). They are thrown eagerly at mechanism construction time when required config fields are absent, not deferred to the first control call.
{% endhint %}
