ergo
Failure.h
Go to the documentation of this file.
1 /* Ergo, version 3.4, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2014 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28 /* The Failure class is used for exception handling. *
29  * It inherits std::exception which means that an instance of this *
30  * class can be caught by catching std::exception& *
31  * The "&" must be there, otherwise the failure message *
32  * will be "cut out". *
33  * Retrieve the message with a call to the member function "what()" *
34  * *
35  * *
36  * \\\|||/// \ (C) Emanuel Rubensson, August, 2005 *
37  * \ ~ ~ / \ *
38  * | @ @ | \ mail: emanuel@theochem.kth.se *
39  * oOo---(_)---oOo---\----------------------------------------------*
40  * */
41 
42 #ifndef FAILURE
43 #define FAILURE
44 #include <exception>
45 namespace mat
46 {
47  class Failure : public std::exception {
48  const char* message;
49  public:
51  :message("Failure: No failure information available")
52  {}
53  explicit Failure (const char* msg)
54  :message(msg)
55  {}
56  virtual ~Failure() throw() {}
57  virtual const char* what() const throw()
58  {return message;}
59  };
60 
61  class Acceptable : public Failure {
62  public:
64  :Failure("Acceptable: No acceptable failure information available")
65  {}
66  explicit Acceptable (const char* msg)
67  :Failure(msg)
68  {}
69  };
70 
71  class AcceptableMaxIter : public Acceptable {
72  int maxiter;
73  public:
75  :Acceptable("AcceptableMaxIter: No acceptable failure information available"),
76  maxiter(0)
77  {}
78  explicit AcceptableMaxIter (const char* msg, int maxi = 0)
79  :Acceptable(msg), maxiter(maxi)
80  {}
81  int get_maxiter() const {
82  return maxiter;
83  }
84  };
85 
86 } /* end namespace */
87 #endif
const char * message
Definition: Failure.h:48
Definition: Failure.h:71
AcceptableMaxIter()
Definition: Failure.h:74
Acceptable(const char *msg)
Definition: Failure.h:66
AcceptableMaxIter(const char *msg, int maxi=0)
Definition: Failure.h:78
Failure(const char *msg)
Definition: Failure.h:53
Definition: allocate.cc:30
int get_maxiter() const
Definition: Failure.h:81
virtual const char * what() const
Definition: Failure.h:57
int maxiter
Definition: Failure.h:72
virtual ~Failure()
Definition: Failure.h:56
Definition: Failure.h:61
Definition: Failure.h:47
Acceptable()
Definition: Failure.h:63
Failure()
Definition: Failure.h:50