diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h index 866492b2544c0717cda185c700ed24d415065e64..6d0295ceb0deeec06ee9425f3594f79160f0e9d6 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h @@ -62,6 +62,8 @@ public: std::string runPythonAlgorithm(const std::string &pythonCode) override; private: + /// Check for null pointer + void checkPtrValid(IReflSettingsTabPresenter *pointer) const; /// The view we are handling IReflMainWindowView *m_view; /// The presenter of tab 'Runs' diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp index 09b9e8e846bd930944c38a80a90ed599e0c5d699..66884b4b604084a4db7c4b77175903b33aef3aea 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp @@ -31,8 +31,7 @@ ReflMainWindowPresenter::~ReflMainWindowPresenter() {} */ std::string ReflMainWindowPresenter::getPlusOptions() const { - if (m_settingsPresenter == nullptr) - throw std::runtime_error("Could not read settings"); + checkPtrValid(m_settingsPresenter); return m_settingsPresenter->getPlusOptions(); } @@ -42,8 +41,7 @@ std::string ReflMainWindowPresenter::getPlusOptions() const { */ std::string ReflMainWindowPresenter::getTransmissionOptions() const { - if (m_settingsPresenter == nullptr) - throw std::runtime_error("Could not read settings"); + checkPtrValid(m_settingsPresenter); return m_settingsPresenter->getTransmissionOptions(); } @@ -53,8 +51,7 @@ std::string ReflMainWindowPresenter::getTransmissionOptions() const { */ std::string ReflMainWindowPresenter::getReductionOptions() const { - if (m_settingsPresenter == nullptr) - throw std::runtime_error("Could not read settings"); + checkPtrValid(m_settingsPresenter); // Request global processing options to 'Settings' presenter return m_settingsPresenter->getReductionOptions(); @@ -65,8 +62,7 @@ std::string ReflMainWindowPresenter::getReductionOptions() const { */ std::string ReflMainWindowPresenter::getStitchOptions() const { - if (m_settingsPresenter == nullptr) - throw std::runtime_error("Could not read settings"); + checkPtrValid(m_settingsPresenter); // Request global post-processing options to 'Settings' presenter return m_settingsPresenter->getStitchOptions(); @@ -142,5 +138,14 @@ ReflMainWindowPresenter::runPythonAlgorithm(const std::string &pythonCode) { return m_view->runPythonAlgorithm(pythonCode); } + +/** Checks for null pointer +* @param pointer :: The pointer +*/ +void ReflMainWindowPresenter::checkPtrValid( + IReflSettingsTabPresenter *pointer) const { + if (pointer == nullptr) + throw std::invalid_argument("Could not read settings"); +} } } \ No newline at end of file