Skip to content

Commit

Permalink
Convert c++ exceptions into scheme exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Dec 23, 2014
1 parent 84913d2 commit 7a7fd87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions opencog/guile/SchemePrimitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,29 @@ 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);
}
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 (...)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/scm/SCMPrimitiveUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down

0 comments on commit 7a7fd87

Please sign in to comment.