Rcpp Version 0.9.10
UncaughtExceptions.r
Go to the documentation of this file.
00001 #!/usr/bin/r -t
00002 #
00003 # Copyright (C) 2009 - 2010  Romain Francois and Dirk Eddelbuettel
00004 #
00005 # This file is part of Rcpp.
00006 #
00007 # Rcpp is free software: you can redistribute it and/or modify it
00008 # under the terms of the GNU General Public License as published by
00009 # the Free Software Foundation, either version 2 of the License, or
00010 # (at your option) any later version.
00011 #
00012 # Rcpp is distributed in the hope that it will be useful, but
00013 # WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 # GNU General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU General Public License
00018 # along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020 require(Rcpp)
00021 require(inline)
00022 funx <- cxxfunction(    
00023         signature(), 
00024         'throw std::range_error("boom"); return R_NilValue ; ', 
00025         plugin = "Rcpp" )
00026 tryCatch(  funx(), "C++Error" = function(e){
00027         cat( sprintf( "C++ exception of class '%s' : %s\n", class(e)[1L], e$message  ) )
00028 } )
00029 # or using a direct handler
00030 tryCatch(  funx(), "std::range_error" = function(e){
00031         cat( sprintf( "C++ exception of class '%s' : %s\n", class(e)[1L], e$message  ) )
00032 } )
00033 # just to check things carry on
00034 print( rnorm(10) )
00035 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines