> 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`\
**Header:** `#include <yams/exceptions.hpp>`\
**Java equivalent:** [Java Exceptions](https://yams.yassrobotics.com/api-reference/java-reference/exceptions.md)\
**Doxygen:** [`yams::exceptions`](https://doxygen.yassrobotics.com/yams/namespaceyams_1_1exceptions.html)

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.

### Gearing exceptions

```cpp
NoStagesGivenException()
explicit InvalidStageGivenException(const std::string& stage)
```

***

## Example

```cpp
try {
    // motor is a SmartMotorController (e.g. a SparkWrapper or TalonFXWrapper)
    yams::mechanisms::positional::Arm arm{&armConfig, &motor};
} catch (const yams::exceptions::ArmConfigurationException& e) {
    fmt::print("Arm config error: {}\n", e.what());
} catch (const yams::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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://yams.yassrobotics.com/api-reference/c++-reference/exceptions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
