Did you ignore a return code? (Use [[nodiscard]]).
Destructor Throw
Never throw from destructor (std::terminate).
Thinking Prompt
Is absence valid?
Yes? → std::optional<T>.
Does caller need details?
Yes? → std::expected<T, E> or Exception.
No? → bool or std::optional.
Is it a Logic Error (Bug)?
Yes? → assert() or std::terminate(). Do not throw for bugs in C++ (Contract Violation).
Trace Up / Down
Trace Up:
Issue: "Program aborted with 'terminate called recursively'."
Cause: An exception was thrown while stack unwinding (in a destructor).
Fix: Fix the destructor. Ensure RAII cleanup is noexcept.
Quick Reference
Mechanism
Cost (Happy)
Cost (Sad)
Use When
std::optional
Branch
Branch
Return may be empty.
std::expected
Branch
Branch
Recoverable error (Parsing).
Exception
Zero
Huge
Rare IO/Resource errors.
Assert
Zero (Release)
Abort
Logic bugs / Invariants.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: 13eholder-modern-cpp-skills-m06-error-handling3description: C++ Error Handling4---56# C++ Error Handling78## Core Question910**Is this error recoverable?**1112- **Yes (Local)**: `std::expected` or return code.13- **Yes (Distant)**: Exceptions (`throw`).14- **No (Bug)**: `assert` or `std::terminate`.1516## Error → Design Question1718| Issue | Design Question |19| ---------------------- | ---------------------------------------------------- |20| **Uncaught Exception** | Did you forget to catch, or throw in `noexcept`? |21| **Silent Failure** | Did you ignore a return code? (Use `[[nodiscard]]`). |22| **Destructor Throw** | Never throw from destructor (`std::terminate`). |2324## Thinking Prompt25261. **Is absence valid?**27 - Yes? → `std::optional<T>`.28292. **Does caller need details?**30 - Yes? → `std::expected<T, E>` or Exception.31 - No? → `bool` or `std::optional`.32333. **Is it a Logic Error (Bug)?**34 - Yes? → `assert()` or `std::terminate()`. Do not throw for bugs in C++ (Contract Violation).3536## Trace Up / Down3738- **Trace Up**:39 - *Issue*: "Program aborted with 'terminate called recursively'."40 - *Cause*: An exception was thrown while stack unwinding (in a destructor).41 - *Fix*: Fix the destructor. Ensure RAII cleanup is `noexcept`.4243## Quick Reference4445| Mechanism | Cost (Happy) | Cost (Sad) | Use When |46| ------------------- | -------------- | ---------- | ---------------------------- |47| **`std::optional`** | Branch | Branch | Return may be empty. |48| **`std::expected`** | Branch | Branch | Recoverable error (Parsing). |49| **Exception** | Zero | Huge | Rare IO/Resource errors. |50| **Assert** | Zero (Release) | Abort | Logic bugs / Invariants. |5152---53> Converted and distributed by [TomeVault](https://tomevault.io/claim/13eholder) — claim your Tome and manage your conversions.54<!-- tomevault:4.0:skill_md:2026-04-11 -->
Run npx skillmds@latest add tomevault-io/13eholder-modern-cpp-skills-m06-error-handling in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
C++ Error Handling It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.