RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample14.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Triggering errors, and surviving to tell the tale
4 //
5 // Copyright (C) 2012 Dirk Eddelbuettel and GPL'ed
6 
7 #include <RInside.h> // for the embedded R via RInside
8 
9 int main(int argc, char *argv[]) {
10 
11  RInside R(argc, argv, false, false, true); // create an embedded R instance -- and interactive
12 
13  try {
14  std::string cmd = "cat(doesNotExist))"; // simple parse error due to double "))"
15  R.parseEvalQNT(cmd); // eval quietly, does not throw on error
16  // parseEvalQ would throw on the error
17 
18  cmd = "cat(doesNotExist)"; // error, but surviving as we are in interactive mode
19  R.parseEvalQ(cmd); // eval quietly, no error thrown
20  // without try() we'd have an error and exit
21 
22  cmd = "cat(\"End of main part\\n\")";
23  R.parseEval(cmd); // eval the string, ignoring any returns
24 
25  } catch( std::exception &ex ) {
26  std::cerr << "Exception caught: " << ex.what() << std::endl;
27  } catch(...) {
28  std::cerr << "C++ exception (unknown reason)" << std::endl;
29  }
30  std::cout << "All done, past catch()\n";
31 
32  exit(0);
33 }
34 
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
void parseEvalQNT(const std::string &line)
Definition: RInside.cpp:374
int main(int argc, char *argv[])