File Coverage

src/xs/catch.h
Criterion Covered Total %
statement 6 6 100.0
branch 5 10 50.0
condition n/a
subroutine n/a
pod n/a
total 11 16 68.7


line stmt bran cond sub pod time code
1             #pragma once
2             #include
3             #include
4             #include
5              
6             namespace xs {
7              
8             using CatchHandlerSimple = std::function;
9             using CatchHandler = std::function;
10              
11             using ExceptionProcessor = std::function;
12             using ExceptionProcessorSimple = std::function;
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 25           template static inline auto throw_guard (CV* context, F&& f) -> decltype(f()) {
23             SV* exc;
24 25 100         try { return f(); }
25 4           catch (...) {
26 4 50         auto tmp = xs::_exc2sv(context);
    50          
27 2 50         if (tmp) exc = tmp.detach();
    0          
28             else exc = newSVpvs("");
29             }
30 2           croak_sv(sv_2mortal(exc));
31             }
32              
33             }