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-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef _psi4_exception_h_
29 #define _psi4_exception_h_
30 
31 #include <cctype>
32 #include <exception>
33 #include <stdexcept>
34 #include <sstream>
35 #include <string.h>
36 
37 #if defined(__GNUC__) || (defined(__ICC) && (__ICC >= 600))
38 # define PSI4_CURRENT_FUNCTION __PRETTY_FUNCTION__
39 #elif defined(__cplusplus) && (__cplusplus >= 201103)
40 #define PSI4_CURRENT_FUNCTION __func__
41 #else
42 #define PSI4_CURRENT_FUNCTION "(unknown)"
43 #endif
44 
45 namespace psi {
46 
47 #define PSIEXCEPTION(message) PsiException(message, __FILE__, __LINE__)
48 #define NOT_IMPLEMENTED_EXCEPTION() NotImplementedException_(PSI4_CURRENT_FUNCTION, __FILE__, __LINE__)
49 
53 class PsiException : public std::runtime_error
54 {
55 
56 private:
57  std::string msg_;
58  const char *file_;
59  int line_;
60 
61 protected:
66  void rewrite_msg(std::string msg) throw();
67 
68 public:
76  std::string message,
77  const char *file,
78  int line
79  ) throw();
80 
81  PsiException(const PsiException &copy) throw();
82 
83  virtual ~PsiException() throw();
84 
85  PsiException &operator=(const PsiException &other)
86  {
87  if (this != &other) {
88  msg_ = other.msg_;
89  file_ = strdup(other.file_);
90  line_ = other.line_;
91  }
92  return *this;
93  }
94 
99  const char *what() const throw();
100 
105  const char *file() const throw();
106 
111  const char *location() const throw();
112 
117  int line() const throw();
118 
119 };
120 
122 {
123 public:
124  NotImplementedException_(const std::string &message,
125  const char *lfile,
126  int lline)
127  : PsiException(message + " function not implemented", lfile, lline)
128  {}
129 };
130 
135 {
136 
137 public:
145  std::string message,
146  const char *file,
147  int line
148  ) throw();
149 
150  virtual ~SanityCheckError() throw();
151 };
152 
156 class SystemError : public PsiException
157 {
158 
159 public:
166  SystemError(
167  int eno,
168  const char *file,
169  int line
170  ) throw();
171 
172  virtual ~SystemError() throw();
173 };
174 
179 {
180 
181 public:
190  std::string module,
191  std::string feature,
192  const char *file,
193  int line
194  ) throw();
195 
196  virtual ~FeatureNotImplemented() throw();
197 };
198 
199 
203 template<class T>
205 {
206 
207 private:
210  std::string resource_name_;
211 
212 protected:
217  const char *description() const throw()
218  {
219  std::stringstream sstr;
220  sstr << "value for " << resource_name_ << " exceeded.\n"
221  << "allowed: " << maxval_ << " actual: " << errorval_;
222  return sstr.str().c_str();
223  }
224 
225 public:
235  std::string resource_name,
236  T maxval,
237  T errorval,
238  const char *f,
239  int l) throw() : PsiException(resource_name, f, l), maxval_(maxval), errorval_(errorval),
240  resource_name_(resource_name)
241  {
242  rewrite_msg(description());
243  }
244 
245  T max_value() const throw()
246  { return maxval_; }
247 
248  T actual_value() const throw()
249  { return errorval_; }
250 
251  virtual ~LimitExceeded<T>() throw()
252  {};
253 };
254 
258 template<class T=double>
259 class StepSizeError : public LimitExceeded<T>
260 {
261 
263 
264 public:
274  std::string resource_name,
275  T max,
276  T actual,
277  const char *file,
278  int line) throw();
279 
280  virtual ~StepSizeError() throw();
281 };
282 
286 template<class T=int>
288 {
289 
291 
292 public:
301  std::string routine_name,
302  T max,
303  const char *file,
304  int line) throw();
305 
306  virtual ~MaxIterationsExceeded() throw();
307 
308 };
309 
313 template<class T=int>
315 {
316 public:
327  std::string routine_name,
328  T max,
329  double desired_accuracy,
330  double actual_accuracy,
331  const char *file,
332  int line) throw();
333 
337  double desired_accuracy() const throw();
338 
342  double actual_accuracy() const throw();
343 
344  virtual ~ConvergenceError() throw();
345 
346 private:
347  double desired_acc_;
348  double actual_acc_;
349 };
350 
354 template<class T=size_t>
356 {
357 
358 public:
367  std::string resource_name,
368  T max,
369  T actual,
370  const char *file,
371  int line) throw();
372 
373  virtual ~ResourceAllocationError() throw();
374 };
375 
380 {
381 
382 private:
386  template<class T>
387  void
388  write_input_msg(std::string msg, std::string param_name, T val) throw();
389 
390 public:
400  std::string msg,
401  std::string param_name,
402  int value,
403  const char *file,
404  int line
405  ) throw();
406 
416  std::string msg,
417  std::string param_name,
418  double value,
419  const char *file,
420  int line
421  ) throw();
422 
432  std::string msg,
433  std::string param_name,
434  std::string value,
435  const char *file,
436  int line
437  ) throw();
438 
447  std::string msg,
448  std::string param_name,
449  const char *file,
450  int line
451  ) throw();
452 };
453 
454 } //end namespace psi exception
455 
456 #endif
const char * file() const
Definition: exception.cc:110
virtual ~PsiException()
Definition: exception.cc:130
T actual_value() const
Definition: exception.h:248
Definition: exception.h:379
double actual_acc_
Definition: exception.h:348
LimitExceeded< T > ParentClass
Definition: exception.h:290
void rewrite_msg(std::string msg)
Definition: exception.cc:94
const char * file_
Definition: exception.h:58
Definition: exception.h:178
T maxval_
Definition: exception.h:208
#define max(a, b)
Definition: svd.cc:38
Definition: exception.h:314
Definition: exception.h:156
NotImplementedException_(const std::string &message, const char *lfile, int lline)
Definition: exception.h:124
Definition: exception.h:355
Definition: exception.h:53
const char * location() const
Definition: exception.cc:122
T max_value() const
Definition: exception.h:245
Definition: exception.h:287
LimitExceeded(std::string resource_name, T maxval, T errorval, const char *f, int l)
Definition: exception.h:234
Definition: exception.h:121
T errorval_
Definition: exception.h:209
std::string resource_name_
Definition: exception.h:210
int line_
Definition: exception.h:59
Definition: exception.h:259
int line() const
Definition: exception.cc:116
LimitExceeded< T > ParentClass
Definition: exception.h:262
PsiException(std::string message, const char *file, int line)
Definition: exception.h:204
std::string msg_
Definition: exception.h:57
Definition: exception.h:134
double desired_acc_
Definition: exception.h:347
const char * description() const
Definition: exception.h:217
Definition: PsiFileImpl.h:39
const char * what() const
Definition: exception.cc:100