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
- For each throw site, identify the appropriate
error_code from error_handling.h
- Change return type from
T to common::Result<T> (or common::VoidResult)
- Replace
throw with return make_error_result<T>(error_code::xxx)
- Update call sites in tests to use
.value() or error checking
- Ensure backward compatibility through clear migration notes
Acceptance Criteria
What
Replace all
throwstatements in public API headers withcommon::Result<T>return types to ensure consistent error handling before API freeze.Part of #670
Why
error_handling.hprovides comprehensivemake_error_result<T>()infrastructure but it's not consistently appliedWhere
Files Affected
include/kcenon/thread/core/cancellation_token.hthrow std::runtime_error("Operation cancelled")include/kcenon/thread/core/thread_pool_impl.hthrow std::invalid_argument("Empty callables vector")include/kcenon/thread/core/cancellable_future.hthrow std::runtime_errorReference
include/kcenon/thread/core/error_handling.h— error code enum and Result utilitiesHow
Technical Approach
error_codefromerror_handling.hTtocommon::Result<T>(orcommon::VoidResult)throwwithreturn make_error_result<T>(error_code::xxx).value()or error checkingAcceptance Criteria
throwstatements remain in public API headerscommon::Result<T>orcommon::VoidResulterror_handling.h