src/xs/catch.h

filter: Statementstmt 100% 2 / 2 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 2 / 2 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/xs/Scope.h ↑ Summary src/xs/typemap/optional.h »
1 #pragma once
2 #include <xs/Sub.h>
3 #include <functional>
4 #include <panda/exception.h>
5  
6 namespace xs {
7  
8 using CatchHandlerSimple = std::function<Sv()>;
9 using CatchHandler = std::function<Sv(const Sub&)>;
10  
11 using ExceptionProcessor = std::function<Sv(Sv& ex, const Sub&)>;
12 using ExceptionProcessorSimple = std::function<Sv(Sv& ex)>;
13  
14 void add_catch_handler (CatchHandlerSimple f);
15 void add_catch_handler (CatchHandler f);
16  
17 void add_exception_processor(ExceptionProcessor f);
18 void add_exception_processor(ExceptionProcessorSimple f);
19  
20 Sv _exc2sv (const Sub&);
21  
22 35 template <typename F> static inline auto throw_guard (CV* context, F&& f) -> decltype(f()) {
23 SV* exc;
24 35 try { return f(); }
25 catch (...) {
26 auto tmp = xs::_exc2sv(context);
27 if (tmp) exc = tmp.detach();
28 else exc = newSVpvs("<empty exception>");
29 }
30 croak_sv(sv_2mortal(exc));
31 }
32  
33 }
« src/xs/Scope.h ↑ Summary src/xs/typemap/optional.h »