Psi4
exception.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2018 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi4_exception_h_
30 #define _psi4_exception_h_
31 
32 #include <cctype>
33 #include <exception>
34 #include <stdexcept>
35 #include <sstream>
36 #include <string.h>
37 
38 #if defined(__GNUC__) || (defined(__ICC) && (__ICC >= 600))
39 # define PSI4_CURRENT_FUNCTION __PRETTY_FUNCTION__
40 #elif defined(__cplusplus) && (__cplusplus >= 201103)
41 #define PSI4_CURRENT_FUNCTION __func__
42 #else
43 #define PSI4_CURRENT_FUNCTION "(unknown)"
44 #endif
45 
46 #include "psi4/pragma.h"
47 
48 namespace psi {
49 
50 #define PSIEXCEPTION(message) PsiException(message, __FILE__, __LINE__)
51 #define NOT_IMPLEMENTED_EXCEPTION() NotImplementedException_(PSI4_CURRENT_FUNCTION, __FILE__, __LINE__)
52 
56 class PSI_API PsiException : public std::runtime_error
57 {
58 
59 private:
60  std::string msg_;
61  const char *file_;
62  int line_;
63 
64 protected:
69  void rewrite_msg(std::string msg) throw();
70 
71 public:
79  std::string message,
80  const char *file,
81  int line
82  ) throw();
83 
84  PsiException(const PsiException &copy) throw();
85 
86  virtual ~PsiException() throw();
87 
88  PsiException &operator=(const PsiException &other)
89  {
90  if (this != &other) {
91  msg_ = other.msg_;
92  file_ = strdup(other.file_);
93  line_ = other.line_;
94  }
95  return *this;
96  }
97 
102  const char *what() const throw();
103 
108  const char *file() const throw();
109 
114  const char *location() const throw();
115 
120  int line() const throw();
121 
122 };
123 
125 {
126 public:
127  NotImplementedException_(const std::string &message,
128  const char *lfile,
129  int lline)
130  : PsiException(message + " function not implemented", lfile, lline)
131  {}
132 };
133 
138 {
139 
140 public:
148  std::string message,
149  const char *file,
150  int line
151  ) throw();
152 
153  virtual ~SanityCheckError() throw();
154 };
155 
159 class SystemError : public PsiException
160 {
161 
162 public:
169  SystemError(
170  int eno,
171  const char *file,
172  int line
173  ) throw();
174 
175  virtual ~SystemError() throw();
176 };
177 
182 {
183 
184 public:
193  std::string module,
194  std::string feature,
195  const char *file,
196  int line
197  ) throw();
198 
199  virtual ~FeatureNotImplemented() throw();
200 };
201 
202 
206 template<class T>
208 {
209 
210 private:
213  std::string resource_name_;
214 
215 protected:
220  const char *description() const throw()
221  {
222  std::stringstream sstr;
223  sstr << "value for " << resource_name_ << " exceeded.\n"
224  << "allowed: " << maxval_ << " actual: " << errorval_;
225  return sstr.str().c_str();
226  }
227 
228 public:
238  std::string resource_name,
239  T maxval,
240  T errorval,
241  const char *f,
242  int l) throw() : PsiException(resource_name, f, l), maxval_(maxval), errorval_(errorval),
243  resource_name_(resource_name)
244  {
245  rewrite_msg(description());
246  }
247 
248  T max_value() const throw()
249  { return maxval_; }
250 
251  T actual_value() const throw()
252  { return errorval_; }
253 
254  virtual ~LimitExceeded<T>() throw()
255  {};
256 };
257 
261 template<class T=double>
262 class StepSizeError : public LimitExceeded<T>
263 {
264 
266 
267 public:
277  std::string resource_name,
278  T max,
279  T actual,
280  const char *file,
281  int line) throw();
282 
283  virtual ~StepSizeError() throw();
284 };
285 
289 template<class T=int>
291 {
292 
294 
295 public:
304  std::string routine_name,
305  T max,
306  const char *file,
307  int line) throw();
308 
309  virtual ~MaxIterationsExceeded() throw();
310 
311 };
312 
316 template<class T=int>
318 {
319 public:
330  std::string routine_name,
331  T max,
332  double desired_accuracy,
333  double actual_accuracy,
334  const char *file,
335  int line) throw();
336 
340  double desired_accuracy() const throw();
341 
345  double actual_accuracy() const throw();
346 
347  virtual ~ConvergenceError() throw();
348 
349 private:
350  double desired_acc_;
351  double actual_acc_;
352 };
353 
357 template<class T=size_t>
359 {
360 
361 public:
370  std::string resource_name,
371  T max,
372  T actual,
373  const char *file,
374  int line) throw();
375 
376  virtual ~ResourceAllocationError() throw();
377 };
378 
383 {
384 
385 private:
389  template<class T>
390  void
391  write_input_msg(std::string msg, std::string param_name, T val) throw();
392 
393 public:
403  std::string msg,
404  std::string param_name,
405  int value,
406  const char *file,
407  int line
408  ) throw();
409 
419  std::string msg,
420  std::string param_name,
421  double value,
422  const char *file,
423  int line
424  ) throw();
425 
435  std::string msg,
436  std::string param_name,
437  std::string value,
438  const char *file,
439  int line
440  ) throw();
441 
450  std::string msg,
451  std::string param_name,
452  const char *file,
453  int line
454  ) throw();
455 };
456 
457 } //end namespace psi exception
458 
459 #endif
T actual_value() const
Definition: exception.h:251
Definition: exception.h:382
double actual_acc_
Definition: exception.h:351
LimitExceeded< T > ParentClass
Definition: exception.h:293
const char * file_
Definition: exception.h:61
Definition: exception.h:181
T maxval_
Definition: exception.h:211
dpdfile4 * file_
Definition: mrcc/mrcc.cc:110
#define max(a, b)
Definition: svd.cc:39
int * T
Definition: stringlist.cc:66
Definition: exception.h:317
Definition: exception.h:159
NotImplementedException_(const std::string &message, const char *lfile, int lline)
Definition: exception.h:127
Definition: exception.h:358
Definition: exception.h:56
T max_value() const
Definition: exception.h:248
Definition: exception.h:290
LimitExceeded(std::string resource_name, T maxval, T errorval, const char *f, int l)
Definition: exception.h:237
Definition: exception.h:124
T errorval_
Definition: exception.h:212
std::string resource_name_
Definition: exception.h:213
#define PSI_API
Definition: pragma.h:153
int line_
Definition: exception.h:62
Definition: exception.h:262
LimitExceeded< T > ParentClass
Definition: exception.h:265
Definition: exception.h:207
std::string msg_
Definition: exception.h:60
Definition: exception.h:137
double desired_acc_
Definition: exception.h:350
const char * description() const
Definition: exception.h:220