m13-domain-error

Standardize C++ domain-error handling with std::runtime_error hierarchies and std::error_code.

14|3|Updated Jan 25, 2026
One-click install
npx skills add https://github.com/13eholder/Modern-Cpp-Skills --skill m13-domain-error-13eholder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m13-domain-error
Source: https://github.com/13eholder/Modern-Cpp-Skills/tree/main/m13-domain-error
Command: npx skills add https://github.com/13eholder/Modern-Cpp-Skills --skill m13-domain-error-13eholder

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Domain errors in C++ can become opaque without clear structure. This guide helps you design exception hierarchies, integrate std::error_code for system errors, and adopt explicit failure paths like std::expected where appropriate.

Core Features & Use Cases

  • Structured exception hierarchies based on std::runtime_error derivatives for domain errors.
  • Integration of system errors via std::error_code to represent OS or library failures.
  • Guidance on using optional/expected patterns to model recoverable errors and to provide context.
  • Real-world use: library APIs that report precise error categories and actionable messages.

Quick Start

Implement a FileError struct derived from std::runtime_error and propagate an associated std::error_code to distinguish domain failures from system errors.

Frequently Asked Questions about m13-domain-error

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure C++ exception hierarchies for domain errors?

Structure C++ exception hierarchies by deriving custom error types from std::runtime_error to represent specific domain failures. This approach ensures predictable failure paths and provides clear, contextual information across module boundaries.

When should I use std::error_code vs exceptions for error handling in C++?

Use std::error_code to represent OS or library system failures, while using std::runtime_error derivatives for domain errors. This integration distinguishes system-level failures from application-specific domain logic errors.

How do I model recoverable errors using std::expected in C++?

Model recoverable C++ errors by adopting optional and std::expected patterns to provide explicit failure paths. These patterns return contextual information without relying on exceptions for predictable error recovery.

What is the best way to propagate system errors across library boundaries in C++?

The best way to propagate system errors across C++ library boundaries is integrating std::error_code with structured exception hierarchies. This standardizes error categories and ensures actionable, precise failure messages.

Can I use std::expected with existing std::runtime_error based exception hierarchies?

You can use std::expected alongside std::runtime_error hierarchies by applying optional and expected patterns for recoverable errors. This combination provides explicit failure paths while maintaining standard exception integration for critical domain failures.