diff --git a/exceptions.h b/exceptions.h new file mode 100644 index 0000000000000000000000000000000000000000..53139cd9b9fe64921407980c28be02b3578cbb41 --- /dev/null +++ b/exceptions.h @@ -0,0 +1,22 @@ +// +// Created by martin on 9/17/18. +// + +#ifndef LIB4NEURO_EXCEPTIONS_H +#define LIB4NEURO_EXCEPTIONS_H + +#include <stdexcept> +#include <boost/type_index.hpp> //TODO Can Boost be included here? + +#ifdef L4N_DEBUG +#define ERR_MSG(msg) std::string(boost::typeindex::type_id_with_cvr<decltype(*this)>().pretty_name()) + "::" + __func__ + "(): " + msg + " (" +__FILE__ + ":" + std::to_string(__LINE__) + ")" +#else +#define ERR_MSG(msg) std::string(boost::typeindex::type_id_with_cvr<decltype(*this)>().pretty_name()) + "::" + __func__ + "(): " + msg +#endif // L4N_DEBUG + +#define THROW_RUNTIME_ERROR(msg) std::runtime_error(ERR_MSG(msg)) // Errors, that can't be detected by looking at the code +#define THROW_LOGIC_ERROR(msg) std::logic_error(ERR_MSG(msg)) // Errors, that can be detected by looking at the code +#define THROW_INVALID_ARGUMENT_ERROR(msg) std::invalid_argument(ERR_MSG(msg)) +#define THROW_NOT_IMPLEMENTED_ERROR(msg) std::logic_error(ERR_MSG("This function is not implemented." + msg)) + +#endif //LIB4NEURO_EXCEPTIONS_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 364be4eea5b461c9d756aac3aa89f8e6c36b122f..4995799f07ba1b2b284300d679d266fec9ecd89c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,6 @@ if ("${BUILD_LIB}" STREQUAL "yes") ${LIB_TYPE} General/ExprtkWrapper.cpp - Exception/Exceptions.cpp ) target_include_directories( @@ -56,7 +55,6 @@ if ("${BUILD_LIB}" STREQUAL "yes") DataSet/DataSet.cpp ErrorFunction/ErrorFunctions.cpp Solvers/DESolver.cpp - Exception/Exceptions.cpp CSVReader/CSVReader.cpp CrossValidator/CrossValidator.cpp NormalizationStrategy/NormalizationStrategy.cpp diff --git a/src/Exception/Exceptions.h b/src/Exception/Exceptions.h deleted file mode 100644 index bd2628ad2e6ac0683d427dcc412ed3992c6ed8c7..0000000000000000000000000000000000000000 --- a/src/Exception/Exceptions.h +++ /dev/null @@ -1,67 +0,0 @@ -// -// Created by martin on 9/17/18. -// - -#ifndef LIB4NEURO_EXCEPTIONS_H -#define LIB4NEURO_EXCEPTIONS_H - -#include <stdexcept> - -namespace lib4neuro { - -/** - * Class representing an error caused by an incorrect - * input/output dimension specification - */ - class InvalidDimension : public std::runtime_error { - public: - - /** - * Constructor with the general error message - */ - InvalidDimension(); - - /** - * Constructor with specific error message - * @param msg Specific error message - */ - explicit InvalidDimension(std::string msg); - }; - -//TODO implement NotImplementedException according to C++17 -/** - * - */ - class NotImplementedException : public std::runtime_error { - public: - - /** - * - */ - NotImplementedException(); - - /** - * - * @param msg - */ - explicit NotImplementedException(std::string msg); - }; - - class FileNotFoundException : public std::runtime_error { - public: - - /** - * - */ - FileNotFoundException(); - - /** - * - * @param msg - */ - FileNotFoundException(std::string msg); - }; - -} - -#endif //LIB4NEURO_EXCEPTIONS_H