Hi, Devin,
I don't whether this is the standard solution.
As I understand, the default error handler in GSL will abort the program
after printing error message. So you need to close it first.
In most time I don't use try-catch with GSL, I detect whether the result is
'nan' or not. Try the code below:
Best,
KK
// [[Rcpp::depends(RcppGSL)]]
#include <RcppGSL.h>
#include <gsl/gsl_sf_hyperg.h>
#include <Rcpp.h>
#include <math.h>
using namespace Rcpp;
// [[Rcpp::export]]
int test()
{
gsl_set_error_handler_off();
printf ("status = %f\n", gsl_sf_hyperg_2F1(1,1,1.1467003,1));
printf ("status = %f\n", gsl_sf_hyperg_2F1(-10.34,2.05,3.05,0.1725));
return 0;
}
On Thu, Dec 11, 2014 at 10:03 AM, Devin <[email protected]> wrote:
> Dear list
>
>
>
> My Rcpp source file contains a *gsl_sf_hyperg_2F1()* function, and for
> some input values to this function the return value is “NaN”, which leads
> in RStudio to an abortion error.
>
>
>
> In order to avoid abortion errors, I try to implement a try/catch
> exception handler:
>
> *// [[Rcpp::depends(RcppGSL)]]*
>
> *#include <RcppGSL.h>*
>
> *#include <gsl/gsl_sf_hyperg.h>*
>
>
>
> *#include <Rcpp.h>*
>
> *#include <math.h>*
>
> *using namespace Rcpp;*
>
>
>
> *// [[Rcpp::export]]*
>
> *int test()*
>
> *{*
>
> * try{*
>
> * gsl_sf_hyperg_2F1(1,1,1.1467003,1); // abortion error since not
> defined*
>
> * }*
>
> * catch(std::domain_error& e){*
>
> * std::cout << "Domain Error occurred!" << std::endl;*
>
> * }*
>
> * return 0;*
>
> *} *
>
>
>
> This seems to be wrong, since it still causes an abortion error in RStudio.
>
>
>
> I appreciate any input
>
>
>
> Thanks
>
> Devin
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
--
Qiang Kou
[email protected]
School of Informatics and Computing, Indiana University
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel