From ec36ca8e710e83067c2829b8ca8c30142512c590 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 8 Jul 2020 15:16:27 +0100 Subject: [PATCH] Nasal CppBind: restrict which exceptions are caught The previous catch policy breaks unit-testing, since CppUnit relies on a special Exception type. This could be made conditional based on testing or not, but trying the simple way initially. --- simgear/nasal/cppbind/detail/to_nasal_helper.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx index a0c76b20..e8d77090 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -101,13 +102,11 @@ namespace nasal { return (*func)(nasal::CallContext(c, me, argc, args)); } - catch(const std::exception& ex) + // CppUnit::Exception inherits std::exception, so restrict ourselves to + // sg_exception + catch (const sg_exception& e) { - naRuntimeError(c, "Fatal error in Nasal call: %s", ex.what()); - } - catch(...) - { - naRuntimeError(c, "Unknown exception in Nasal call."); + naRuntimeError(c, "Fatal error in Nasal call: %s", e.what()); } return naNil();