diff --git a/src/include/List.h b/src/include/List.h index c0f859922f6238be2b193074b1c82b15046e5973..98fa3b12e96fe607d4945379f033f3fdf19b6b07 100644 --- a/src/include/List.h +++ b/src/include/List.h @@ -12,39 +12,29 @@ */ class ListOutOfBoundsException: public std::exception { protected: - //! \brief Minimum index defined in the List. - int min_index; - //! \brief Maximum index defined in the List. - int max_index; - //! \brief List index requested by user. - int requested_index; + //! Description of the problem. + std::string message; public: - /** - * \brief Exception instance constructor. - * - * \param requested: `int` The index that was requested. - * \param min: `int` The minimum index allowed by the list. - * \param max: `int` The maximum index allowed by the list. - */ - ListOutOfBoundsException(int requested, int min, int max) { - min_index = min; - max_index = max; - requested_index = requested; - } - /** - * \brief Exception message. - */ - virtual const char* what() const throw() { - std::string message = "Error: requested index "; - message += requested_index; - message += " is out of range ["; - message += min_index; - message += ", "; - message += (max_index - 1); - message += "]"; - return message.c_str(); - } + /** + * \brief Exception instance constructor. + * + * \param requested: `int` The index that was requested. + * \param min: `int` The minimum index allowed by the list. + * \param max: `int` The maximum index allowed by the list. + */ + ListOutOfBoundsException(int requested, int min, int max) { + message = "Error: requested index " + std::to_string(requested) + + " out of list allowed bounds [" + std::to_string(min) + ", " + + std::to_string(max - 1) + "]"; + } + + /** + * \brief Exception message. + */ + virtual const char* what() const throw() { + return message.c_str(); + } }; /** @@ -62,7 +52,7 @@ public: * a contiguous array of type T[SIZE] that can be used for indexed access. */ template<class T> class List { - protected: +protected: int size; //!< Size of the List. struct element { T value; //!< Value of the list element. @@ -72,7 +62,7 @@ template<class T> class List { *first, //!< Pointer to the first element in the List. *last; //!< Pointer to the last element in the List. - public: +public: /*! \brief List constructor. * * Use the constructor `List<T>([int length])` to create a new list with a given @@ -176,7 +166,7 @@ template<class T> class List { */ void set(int index, T value) { if (index < 0 || index > size - 1) { - throw ListOutOfBoundsException(index, 0, size - 1); + throw ListOutOfBoundsException(index, 0, size - 1); } current = last; for (int i = size - 1; i > index; i--) current = current->p_prev; diff --git a/src/libnptm/Configuration.cpp b/src/libnptm/Configuration.cpp index 96d055a11f555c217044cec6802461dd465effd7..ac5764de372b66af92a90e3e41b5a56c0dc4c820 100644 --- a/src/libnptm/Configuration.cpp +++ b/src/libnptm/Configuration.cpp @@ -265,7 +265,7 @@ ScattererConfiguration* ScattererConfiguration::from_binary(string file_name, st try { xi_vec = new double[nxi](); } catch (const bad_alloc &ex) { - throw UnrecognizedConfigurationException("Wrong parameter set: invalid number of scales " + nxi); + throw UnrecognizedConfigurationException("Wrong parameter set: invalid number of scales " + to_string(nxi)); } for (int i = 0; i < nxi; i++) { input.read(reinterpret_cast<char *>(&(xi_vec[i])), sizeof(double)); @@ -285,7 +285,7 @@ ScattererConfiguration* ScattererConfiguration::from_binary(string file_name, st try { rcf_vector[i115 - 1] = new double[nsh](); } catch (const bad_alloc &ex) { - throw UnrecognizedConfigurationException("Wrong parameter set: invalid number of layers " + nsh); + throw UnrecognizedConfigurationException("Wrong parameter set: invalid number of layers " + to_string(nsh)); } for (int nsi = 0; nsi < nsh; nsi++) { input.read(reinterpret_cast<char *>(&(rcf_vector[i115 - 1][nsi])), sizeof(double));