[Rinside-commits] r265 - in pkg: . inst/examples/standard

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 16 03:37:53 CEST 2012


Author: edd
Date: 2012-10-16 03:37:50 +0200 (Tue, 16 Oct 2012)
New Revision: 265

Added:
   pkg/inst/examples/standard/rinside_sample14.cpp
Modified:
   pkg/ChangeLog
Log:
new example to show how error is survived in interactive mode


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2012-10-16 01:26:19 UTC (rev 264)
+++ pkg/ChangeLog	2012-10-16 01:37:50 UTC (rev 265)
@@ -8,6 +8,9 @@
 	* inst/examples/standard/rinside_sample13.cpp: New example
 	illustrating the new more fault-tolerant modes
 
+	* inst/examples/standard/rinside_sample14.cpp: New example
+	illustrating the new more fault-tolerant modes with interactive mode 
+
 2012-10-11  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/RInside.h: Added non-throwing variants of parseEval()

Added: pkg/inst/examples/standard/rinside_sample14.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample14.cpp	                        (rev 0)
+++ pkg/inst/examples/standard/rinside_sample14.cpp	2012-10-16 01:37:50 UTC (rev 265)
@@ -0,0 +1,34 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Triggering errors, and surviving to tell the tale
+//
+// Copyright (C) 2012  Dirk Eddelbuettel and GPL'ed 
+
+#include <RInside.h>                    // for the embedded R via RInside
+
+int main(int argc, char *argv[]) {
+
+    RInside R(argc, argv, false, false, true);  // create an embedded R instance -- and interactive
+    
+    try {
+        std::string cmd = "cat(doesNotExist))"; // simple parse error due to double "))"
+        R.parseEvalQNT(cmd); 		        // eval quietly, does not throw on error
+        					// parseEvalQ would throw on the error
+
+        cmd = "cat(doesNotExist)"; 		// error, but surviving as we are in interactive mode
+        R.parseEvalQ(cmd); 		        // eval quietly, no error thrown
+        					// without try() we'd have an error and exit
+
+        cmd = "cat(\"End of main part\\n\")";
+        R.parseEval(cmd); 		        // eval the string, ignoring any returns
+
+    } catch( std::exception &ex ) {
+	std::cerr << "Exception caught: " << ex.what() << std::endl;
+    } catch(...) { 
+	std::cerr << "C++ exception (unknown reason)" << std::endl;
+    }
+    std::cout << "All done, past catch()\n";
+
+    exit(0);
+}
+



More information about the Rinside-commits mailing list