FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/cpp11test/src/safe.cpp at main · josh28x/cpp11 · GitHub
josh28x
cpp11
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
cpp11test
/
src
/
safe.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (27 loc) · 806 Bytes
Breadcrumbs
cpp11
/
cpp11test
/
src
/
safe.cpp
Copy path
File metadata and controls
33 lines (27 loc) · 806 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
include
<
cstring
>
#
include
"
cpp11/doubles.hpp
"
#
include
"
cpp11/protect.hpp
"
[[cpp11::register]]
SEXP
cpp11_safe_
(
SEXP
x_sxp) {
SEXP
err = R_NilValue;
const
size_t
ERROR_SIZE
=
2048
;
char
buf[
ERROR_SIZE
] =
"
"
;
try
{
const
cpp11::doubles
x
(x_sxp);
//
Rf_error("R error"); // This will not call dtors
//
throw std::runtime_error("C++ error");
//
cpp11::unwind_protect([&]() { Rf_error("R error"); });
SEXP
out =
cpp11::unwind_protect
([&] {
return
Rf_allocVector
(
REALSXP
,
1
); });
return
out;
}
catch
(cpp11::unwind_exception& e) {
err = e.
token
;
}
catch
(std::exception& e) {
strncpy
(buf, e.
what
(),
ERROR_SIZE
-
1
);
}
if
(buf[
0
] !=
'
\0
'
) {
Rf_error
(
"
%s
"
, buf);
}
else
if
(err != R_NilValue) {
R_ContinueUnwind
(err);
}
return
R_NilValue;
}
Back
|
FazBrowse Home
|
New Git URL