Skip to content

Replace throw statements with Result<T> in public API #671

Description

@kcenon

What

Replace all throw statements in public API headers with common::Result<T> return types to ensure consistent error handling before API freeze.

Part of #670

Why

  • Public API currently mixes exception-based and Result-based error handling
  • error_handling.h provides comprehensive make_error_result<T>() infrastructure but it's not consistently applied
  • v1.0 API stability requires a single, predictable error handling pattern
  • Throwing exceptions from a threading library can cause undefined behavior if not caught at thread boundaries

Where

Files Affected

File Line(s) Issue
include/kcenon/thread/core/cancellation_token.h 147 throw std::runtime_error("Operation cancelled")
include/kcenon/thread/core/thread_pool_impl.h 83 throw std::invalid_argument("Empty callables vector")
include/kcenon/thread/core/cancellable_future.h 94, 113, 220, 227 Multiple throw std::runtime_error

Reference

  • include/kcenon/thread/core/error_handling.h — error code enum and Result utilities

How

Technical Approach

  1. For each throw site, identify the appropriate error_code from error_handling.h
  2. Change return type from T to common::Result<T> (or common::VoidResult)
  3. Replace throw with return make_error_result<T>(error_code::xxx)
  4. Update call sites in tests to use .value() or error checking
  5. Ensure backward compatibility through clear migration notes

Acceptance Criteria

  • Zero throw statements remain in public API headers
  • All modified functions return common::Result<T> or common::VoidResult
  • Error codes are appropriate and documented in error_handling.h
  • All existing tests updated and passing
  • No new compiler warnings introduced

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions