xerus
a general purpose tensor library
exceptions.h
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
25 #pragma once
26 
27 #include <exception>
28 #include <sstream>
29 #include "stringFromTo.h"
30 
31 namespace xerus {
32  namespace misc {
37  class generic_error : public std::exception {
38  public:
40  std::string error_info;
41 
43  generic_error();
44 
46  generic_error(const generic_error &_other) noexcept;
47 
48  const char* what() const noexcept override;
49  };
50 
52  template<typename error_t, class T>
53  typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
54  operator<< (error_t &o, const T &_info) noexcept {
55  o.error_info += to_string(_info);
56  return o;
57  }
58 
60  template<typename error_t, class T>
61  typename std::enable_if<std::is_base_of<generic_error, error_t>::value, error_t&>::type
62  operator<< (error_t &&o, const T &_info) noexcept {
63  o.error_info += to_string(_info);
64  return o;
65  }
66  }
67 }
68 
73 #define XERUS_THROW(...) throw (__VA_ARGS__ << "\nexception thrown in function: " << (__func__) << " (" << (__FILE__) <<" : " << (__LINE__) << ")\n")
Header file for some elementary string manipulation routines.
The main namespace of xerus.
Definition: basic.h:37
STL namespace.
const char * what() const noexcept override
Definition: exceptions.cpp:34
The xerus exception class.
Definition: exceptions.h:37
generic_error()
: Normal constructor without preset error_info.
Definition: exceptions.cpp:29
static XERUS_force_inline std::string to_string(const bool obj)
Definition: stringFromTo.h:41
std::ostream & operator<<(std::ostream &_out, const std::tuple< Tp... > &_tuple)
Allow to pipe tuples to ostreams.
std::string error_info
String containing all relevant information concerning this error.
Definition: exceptions.h:40