From 7a7fd87b34a98002c2de4bcf64c9afdfb203e15d Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 23 Dec 2014 12:22:40 -0600 Subject: [PATCH] Convert c++ exceptions into scheme exceptions --- opencog/guile/SchemePrimitive.cc | 23 +++++++++++++++-------- tests/scm/SCMPrimitiveUTest.cxxtest | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/opencog/guile/SchemePrimitive.cc b/opencog/guile/SchemePrimitive.cc index a8b72b47d3c..8f3421acfed 100644 --- a/opencog/guile/SchemePrimitive.cc +++ b/opencog/guile/SchemePrimitive.cc @@ -111,7 +111,9 @@ SCM PrimitiveEnviron::do_call(SCM sfe, SCM arglist) // If the C++ code throws any exceptions, and no one else // has caught them, then we have to catch them, and print - // an error message to the shell. + // an error message to the shell. Actually, we'll be + // quasi-nice about this, and convert the C++ exception + // into a scheme exception. try { rc = fe->invoke(arglist); @@ -119,14 +121,19 @@ SCM PrimitiveEnviron::do_call(SCM sfe, SCM arglist) catch (const std::exception& ex) { const char *msg = ex.what(); + + // Should we even bother to log this? + logger().info("Guile caught C++ exception: %s", msg); + // scm_misc_error(fe->get_name(), msg, SCM_EOL); - scm_error_scm( - scm_from_locale_symbol("C++ exception"), - scm_from_locale_string(fe->get_name()), - scm_from_locale_string(msg), - SCM_EOL, - SCM_EOL); - logger().error("Guile caught C++ exception: %s", msg); + scm_throw( + scm_from_locale_symbol(msg), + scm_cons( + scm_from_locale_string("C++ exception"), + scm_cons( + scm_from_locale_string(fe->get_name()), + SCM_EOL))); + // Hmm. scm_throw never returns. } catch (...) { diff --git a/tests/scm/SCMPrimitiveUTest.cxxtest b/tests/scm/SCMPrimitiveUTest.cxxtest index 9b4ca694841..eb11ffec35f 100644 --- a/tests/scm/SCMPrimitiveUTest.cxxtest +++ b/tests/scm/SCMPrimitiveUTest.cxxtest @@ -92,7 +92,7 @@ class MyExampleClass // Throw exception on purpose Handle my_other_func(Handle h) { - throw (RuntimeException(TRACE_INFO, "Don't panic!! Threw exception %d on purpose.", id)); + throw (InvalidParamException(TRACE_INFO, "Don't panic!! Threw exception %d on purpose.", id)); return Handle::UNDEFINED; } };