schwz  Generated automatically from develop
exception.hpp (35a1195)
1 
2 /*******************************<SCHWARZ LIB LICENSE>***********************
3 Copyright (c) 2019, the SCHWARZ LIB authors
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ******************************<SCHWARZ LIB LICENSE>*************************/
33 
34 #ifndef exception_hpp
35 #define exception_hpp
36 
37 
38 #include <exception>
39 #include <string>
40 
41 
42 class Error : public std::exception {
43 public:
50  Error(const std::string &file, int line, const std::string &what)
51  : what_(file + ":" + std::to_string(line) + ": " + what)
52  {}
53 
58  virtual const char *what() const noexcept override { return what_.c_str(); }
59 
60 private:
61  const std::string what_;
62 };
63 
64 
65 class NotImplemented : public Error {
66 public:
73  NotImplemented(const std::string &file, int line, const std::string &func)
74  : Error(file, line, func + " is not implemented")
75  {}
76 };
77 
78 
79 class ModuleNotImplemented : public Error {
80 public:
88  ModuleNotImplemented(const std::string &file, int line,
89  const std::string &module, const std::string &func)
90  : Error(file, line, module + " in " + func + " is not implemented")
91  {}
92 };
93 
94 
99 class BadDimension : public Error {
100 public:
112  BadDimension(const std::string &file, int line, const std::string &func,
113  const std::string &op_name, std::size_t op_num_rows,
114  std::size_t op_num_cols, const std::string &clarification)
115  : Error(file, line,
116  func + ": Object " + op_name + " has dimensions [" +
117  std::to_string(op_num_rows) + " x " +
118  std::to_string(op_num_cols) + "]: " + clarification)
119  {}
120 };
121 
122 
126 class CudaError : public Error {
127 public:
135  CudaError(const std::string &file, int line, const std::string &func,
136  int error_code)
137  : Error(file, line, func + ": " + get_error(error_code))
138  {}
139 
140 private:
141  static std::string get_error(int error_code);
142 };
143 
144 
148 class CusparseError : public Error {
149 public:
157  CusparseError(const std::string &file, int line, const std::string &func,
158  int error_code)
159  : Error(file, line, func + ": " + get_error(error_code))
160  {}
161 
162 private:
163  static std::string get_error(int error_code);
164 };
165 
166 
170 class MetisError : public Error {
171 public:
180  MetisError(const std::string &file, int line, const std::string &func,
181  int error_code)
182  : Error(file, line, func + ": " + get_error(error_code))
183  {}
184 
185 private:
186  static std::string get_error(int error_code);
187 };
188 
189 
193 class UmfpackError : public Error {
194 public:
203  UmfpackError(const std::string &file, int line, const std::string &func,
204  int error_code)
205  : Error(file, line, func + ": " + get_error(error_code))
206  {}
207 
208 private:
209  static std::string get_error(int error_code);
210 };
211 
212 
213 #endif // exception.hpp
ModuleNotImplemented(const std::string &file, int line, const std::string &module, const std::string &func)
Initializes a NotImplemented error.
Definition: exception.hpp:88
Definition: exception.hpp:42
CusparseError(const std::string &file, int line, const std::string &func, int error_code)
Initializes a cuSPARSE error.
Definition: exception.hpp:157
CusparseError is thrown when a cuSPARSE routine throws a non-zero error code.
Definition: exception.hpp:148
MetisError is thrown when a METIS routine throws a non-zero error code.
Definition: exception.hpp:170
CudaError(const std::string &file, int line, const std::string &func, int error_code)
Initializes a CUDA error.
Definition: exception.hpp:135
UmfpackError is thrown when a METIS routine throws a non-zero error code.
Definition: exception.hpp:193
Definition: exception.hpp:65
STL namespace.
BadDimension is thrown if an operation is being applied to a LinOp with bad dimensions.
Definition: exception.hpp:99
BadDimension(const std::string &file, int line, const std::string &func, const std::string &op_name, std::size_t op_num_rows, std::size_t op_num_cols, const std::string &clarification)
Initializes a bad dimension error.
Definition: exception.hpp:112
virtual const char * what() const noexcept override
Returns a human-readable string with a more detailed description of the error.
Definition: exception.hpp:58
UmfpackError(const std::string &file, int line, const std::string &func, int error_code)
Initializes a METIS error.
Definition: exception.hpp:203
CudaError is thrown when a CUDA routine throws a non-zero error code.
Definition: exception.hpp:126
Error(const std::string &file, int line, const std::string &what)
Initializes an error.
Definition: exception.hpp:50
NotImplemented(const std::string &file, int line, const std::string &func)
Initializes a NotImplemented error.
Definition: exception.hpp:73
Definition: exception.hpp:79
MetisError(const std::string &file, int line, const std::string &func, int error_code)
Initializes a METIS error.
Definition: exception.hpp:180