27#include <system_error>
92 const std::string& module =
"") {
101 const std::string& module,
102 const std::string& details) {
128class exception_mapper {
137 "Non-standard exception (not derived from std::exception)"};
172template<
typename T,
typename F>
175 return ok<T>(func());
178 catch (
const std::bad_alloc& e) {
182 catch (
const std::invalid_argument& e) {
186 catch (
const std::out_of_range& e) {
190 catch (
const std::system_error& e) {
192 std::string(
"std::system_error: ") + e.code().category().name()});
195 catch (
const std::logic_error& e) {
199 catch (
const std::runtime_error& e) {
203 catch (
const std::exception& e) {
230 catch (
const std::bad_alloc& e) {
234 catch (
const std::invalid_argument& e) {
238 catch (
const std::out_of_range& e) {
242 catch (
const std::system_error& e) {
244 std::string(
"std::system_error: ") + e.code().category().name()});
247 catch (
const std::logic_error& e) {
251 catch (
const std::runtime_error& e) {
255 catch (
const std::exception& e) {
279#define COMMON_RETURN_IF_ERROR(expr) \
281 auto _result_temp = (expr); \
282 if (_result_temp.is_err()) { \
283 return _result_temp.error(); \
294#define COMMON_ASSIGN_OR_RETURN(decl, expr) \
295 auto _result_##decl = (expr); \
296 if (_result_##decl.is_err()) { \
297 return _result_##decl.error(); \
299 decl = std::move(_result_##decl).value()
307#define COMMON_RETURN_ERROR_IF(condition, code, message, module) \
310 return kcenon::common::error_info{code, message, module}; \
320#define COMMON_RETURN_ERROR_IF_WITH_DETAILS(condition, code, message, module, details) \
323 return kcenon::common::error_info{code, message, module, details}; \
Result type for error handling with member function support.
static error_info map_unknown_exception(const std::string &module="")
Map unknown exception (catch-all)
static error_info map_generic_exception(const std::exception &e, const std::string &module="")
Map generic exception.
Backward compatibility layer for error codes.
constexpr int OUT_OF_MEMORY
constexpr int INVALID_ARGUMENT
constexpr int INTERNAL_ERROR
Result< T > make_error(int code, const std::string &message, const std::string &module="")
Create an error result with code and message.
Result< std::monostate > VoidResult
Specialized Result for void operations.
Result< T > try_catch(F &&func, const std::string &module="")
Convert exception to Result with automatic error code mapping.
VoidResult err(const error_info &error)
Factory function to create error VoidResult.
VoidResult ok()
Create a successful void result.
VoidResult try_catch_void(F &&func, const std::string &module="")
Convert exception to VoidResult with automatic error code mapping.
Consolidated core types for Result<T> pattern.
Standard error information used by Result<T>.