Commit d925ba39 authored by Sebastian Wolf's avatar Sebastian Wolf

Hopefully fixed xerus exceptions

parent ad80999d
Pipeline #1863 failed with stages
in 31 seconds
......@@ -37,30 +37,17 @@ namespace xerus {
class generic_error : public std::exception {
public:
///@brief String containing all relevant information concerning this error.
std::stringstream error_info;
std::string errorInfo;
/// @brief: Normal constructor without preset error_info.
generic_error();
/// @brief Standard copy constructor.
generic_error(const generic_error &_other) noexcept;
const char* what() const noexcept override;
const char* what() const noexcept override { return errorInfo.c_str(); }
};
/// @brief The pipe operator allows to add everything that can be converted to string to the error_info and derived exceptions.
template<typename error_t, class T>
typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
operator<< (error_t &o, const T &_info) noexcept {
o.error_info << to_string(_info);
return o;
}
/// @brief The pipe operator allows to add everything that can be converted to string to the error_info and derived exceptions.
template<typename error_t, class T>
typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
operator<< (error_t &&o, const T &_info) noexcept {
o.error_info << to_string(_info);
template<typename error_t, class T, typename std::enable_if<std::is_base_of<generic_error, std::remove_cvref_t<error_t>>::value, int>::type = 0>
std::remove_cvref_t<error_t>& operator<<(error_t&& o, const T& _info) noexcept {
std::ostringstream errorStream(o.errorInfo, std::ios_base::ate | std::ios_base::out);
errorStream << _info;
o.errorInfo = errorStream.str();
return o;
}
}
......
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2019 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
/**
* @file
* @brief Implementation of the generic_error class.
*/
#include <xerus/misc/exceptions.h>
namespace xerus {
namespace misc {
generic_error::generic_error() {}
generic_error::generic_error(const generic_error &_other) noexcept {
error_info << _other.error_info.rdbuf();
}
const char* generic_error::what() const noexcept {
return error_info.str().c_str();
}
} // namespace misc
} // namespace xerus
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment