#pragma once #include #include #include namespace xs { using CatchHandlerSimple = std::function; using CatchHandler = std::function; using ExceptionProcessor = std::function; using ExceptionProcessorSimple = std::function; void add_catch_handler (CatchHandlerSimple f); void add_catch_handler (CatchHandler f); void add_exception_processor(ExceptionProcessor f); void add_exception_processor(ExceptionProcessorSimple f); Sv _exc2sv (const Sub&); template static inline auto throw_guard (CV* context, F&& f) -> decltype(f()) { SV* exc; try { return f(); } catch (...) { auto tmp = xs::_exc2sv(context); if (tmp) exc = tmp.detach(); else exc = newSVpvs(""); } croak_sv(sv_2mortal(exc)); } }