Skip to content
Snippets Groups Projects
exceptions.h 1.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    #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 + ""
    
    #define THROW_RUNTIME_ERROR(msg) throw std::runtime_error(ERR_MSG(msg))  // Errors, that can't be detected by looking at the code
    #define THROW_LOGIC_ERROR(msg) throw std::logic_error(ERR_MSG(msg))  // Errors, that can be detected by looking at the code
    #define THROW_INVALID_ARGUMENT_ERROR(msg) throw std::invalid_argument(ERR_MSG(msg))
    
    #define THROW_NOT_IMPLEMENTED_ERROR(msg) throw std::logic_error(ERR_MSG("This function is not implemented. " + msg))
    
    #define THROW_OUT_OF_RANGE_ERROR(msg) throw std::out_of_range(ERR_MSG(msg))