From a1353e77be48de80809109594c2435d890751c78 Mon Sep 17 00:00:00 2001 From: "M. Eric Irrgang" Date: Fri, 12 Oct 2018 21:34:27 +0300 Subject: [PATCH] gmxapi::UsageError Introduce gmxapi exception UsageError for invalid usage of gmxapi. getMdrunnerSignal() now throws UsageError instead of asserting on argument validity. Change-Id: Ib010a998546ac96a83126ef941822b7e355d0784 --- src/api/cpp/include/gmxapi/exceptions.h | 13 +++++++++++++ src/api/cpp/include/gmxapi/md/mdsignals.h | 1 + src/api/cpp/mdsignals.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/api/cpp/include/gmxapi/exceptions.h b/src/api/cpp/include/gmxapi/exceptions.h index 280c39e643..34272a825c 100644 --- a/src/api/cpp/include/gmxapi/exceptions.h +++ b/src/api/cpp/include/gmxapi/exceptions.h @@ -172,6 +172,19 @@ class NotImplementedError : public BasicException using BasicException::BasicException; }; +/*! + * \brief Unacceptable API usage. + * + * Usage error. Examples include calling a function with invalid arguments. + * + * \ingroup gmxapi_exceptions + */ +class UsageError : public BasicException +{ + public: + using BasicException::BasicException; +}; + } // end namespace gmxapi #endif // header guard diff --git a/src/api/cpp/include/gmxapi/md/mdsignals.h b/src/api/cpp/include/gmxapi/md/mdsignals.h index 17a6ac13c1..28abd58d7e 100644 --- a/src/api/cpp/include/gmxapi/md/mdsignals.h +++ b/src/api/cpp/include/gmxapi/md/mdsignals.h @@ -131,6 +131,7 @@ class Signal * \return Callable function object handle to issue a stop signal. * * \throws gmxapi::NotImplementedError for unknown values of signal. + * \throws gmxapi::UsageError for invalid resources argument. * * \ingroup gmxapi_md */ diff --git a/src/api/cpp/mdsignals.cpp b/src/api/cpp/mdsignals.cpp index 910838c1a6..da00f81e6e 100644 --- a/src/api/cpp/mdsignals.cpp +++ b/src/api/cpp/mdsignals.cpp @@ -178,8 +178,10 @@ Signal getMdrunnerSignal(SessionResources *resources, throw gmxapi::NotImplementedError("This signaller only handles stop signals."); } - // TODO: replace with an exception. - GMX_RELEASE_ASSERT(resources, "Caller must provide a valid SessionResources to getMdrunnerSignal."); + if (resources == nullptr) + { + throw gmxapi::UsageError("Caller must provide a valid SessionResources to getMdrunnerSignal."); + } auto signaller = resources->getMdrunnerSignal(signal); -- 2.11.4.GIT