|
2 | 2 | //
|
3 | 3 | // macros.h: Rcpp R/C++ interface class library -- Rcpp macros
|
4 | 4 | //
|
5 |
| -// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois |
6 | 6 | //
|
7 | 7 | // This file is part of Rcpp.
|
8 | 8 | //
|
|
27 | 27 | #define RCPP_GET_CLASS(x) Rf_getAttrib(x, R_ClassSymbol)
|
28 | 28 |
|
29 | 29 | #ifndef BEGIN_RCPP
|
30 |
| -#define BEGIN_RCPP try { |
| 30 | +#define BEGIN_RCPP \ |
| 31 | + int rcpp_output_type = 0 ; \ |
| 32 | + SEXP rcpp_output_condition = R_NilValue ; \ |
| 33 | + try { |
31 | 34 | #endif
|
32 | 35 |
|
33 | 36 | #ifndef VOID_END_RCPP
|
34 |
| -#define VOID_END_RCPP \ |
35 |
| - } \ |
36 |
| - catch (Rcpp::internal::InterruptedException &__ex__) { \ |
37 |
| - Rf_onintr(); \ |
38 |
| - } \ |
39 |
| - catch (std::exception &__ex__) { \ |
40 |
| - forward_exception_to_r(__ex__); \ |
41 |
| - } \ |
42 |
| - catch (...) { \ |
43 |
| - ::Rf_error("c++ exception (unknown reason)"); \ |
44 |
| - } |
| 37 | +#define VOID_END_RCPP \ |
| 38 | + } \ |
| 39 | + catch( Rcpp::internal::InterruptedException &__ex__) { \ |
| 40 | + rcpp_output_type = 1 ; \ |
| 41 | + } \ |
| 42 | + catch( std::exception& __ex__ ){ \ |
| 43 | + rcpp_output_type = 2 ; \ |
| 44 | + rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \ |
| 45 | + } catch( ... ){ \ |
| 46 | + rcpp_output_type = 2 ; \ |
| 47 | + rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \ |
| 48 | + } \ |
| 49 | + if( rcpp_output_type == 1 ){ \ |
| 50 | + Rf_onintr() ; \ |
| 51 | + } \ |
| 52 | + if( rcpp_output_type == 2 ){ \ |
| 53 | + SEXP stop_sym = Rf_install( "stop" ) ; \ |
| 54 | + SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \ |
| 55 | + Rf_eval( expr, R_GlobalEnv ) ; \ |
| 56 | + } |
45 | 57 | #endif
|
46 | 58 |
|
47 | 59 | #ifndef END_RCPP
|
|
0 commit comments