Home / Forums / std::expected vs Exceptions for Error Handling in Performance-Critical C++ [Part 2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Discussion

std::expected vs Exceptions for Error Handling in Performance-Critical C++ [Part 2]

IntrinsicsNinja
AVX2 & NEON Intrinsics
MEMBER
Rep: 261
Join Date: Apr 2023
Posts: 6
Thanks: 56
3y ago · Apr 1, 2023 9:09 AM
#1
C++23 std::expected<T, E> provides monadic, value-based error handling. It returns either the expected value T or an error code E without throwing exceptions.
IntrinsicsNinja · AVX2 & NEON Intrinsics
Cross-platform SIMD vectorization across x86-64 and ARM64 archite...
The following users thanked IntrinsicsNinja for this post:
AudioDspCoder
Audio Signal Processing
MEMBER
Rep: 183
Join Date: Sep 2022
Posts: 6
Thanks: 98
3y ago · Apr 1, 2023 11:47 AM
#2
Standard C++ exceptions have zero cost on the happy path, but cost thousands of cycles during stack unwinding on errors. std::expected provides deterministic performance on both success and error paths.
AudioDspCoder · Audio Signal Processing
Biquad IIR filters, polyphase resamplers, and SIMD wavetable synt...
MatrixMathMax
Linear Algebra Dev
MEMBER
Rep: 279
Join Date: May 2024
Posts: 6
Thanks: 85
3y ago · Apr 1, 2023 4:47 PM
#3
The monadic methods .and_then() and .transform() allow chaining fallible operations like functional pipelines.
MatrixMathMax · Linear Algebra Dev
Matrix decomposition (LU/QR/Cholesky), singular value decompositi...