CppNoddy  0.92
Loading...
Searching...
No Matches
Exceptions.h
Go to the documentation of this file.
1/// \file Exceptions.h
2/// The collection of CppNoddy exceptions
3
4#ifndef EXCEPTIONS_H
5#define EXCEPTIONS_H
6
7#include <string>
8#include <iostream>
9#include <stdexcept>
10
11// Note: instantiation of any of these exceptions will force
12// info warning to cout without requiring a what() call if
13// WHAT is defined here
14#define WHAT
15
16namespace CppNoddy {
17
18 /// An exception to indicate that an error has
19 /// been detected in an external (LAPACK) routine
20 class ExceptionExternal : public std::runtime_error {
21 public:
22 ExceptionExternal(const std::string &problem, const int &ifail = 0) :
23 std::runtime_error(problem) {
24#ifdef WHAT
25 error_header();
26 std::cout << problem << "\n";
27 std::cout << " External library failure \n";
28 std::cout << " Returned error code = " << ifail << "\n\n";
29#endif
30
31 }
32
33 private:
34
35 void error_header() {
36 std::cout << "----------------------------------------------------\n";
37 std::cout << " Error: A CppNoddy routine has had an EXTERNAL \n";
38 std::cout << " library problem! \n";
39 std::cout << "----------------------------------------------------\n";
40 }
41
42 };
43
44
45 /// An exception class to be thrown when a container
46 /// of incorrect geometry used in any class/method.
47 class ExceptionGeom : public std::runtime_error {
48 public:
49 ExceptionGeom(const std::string &problem, const std::size_t &size1, const std::size_t &size2) :
50 std::runtime_error(problem) {
51#ifdef WHAT
52 error_header();
53 std::cout << problem << "\n";
54 std::cout << " One dimensional container problem \n";
55 std::cout << " Container 1 size is " << size1 << "\n";
56 std::cout << " Container 2 size is " << size2 << "\n\n";
57#endif
58
59 }
60
61 ExceptionGeom(const std::string &problem, const std::size_t &size1, const std::size_t &size2,
62 const std::size_t &size3, const std::size_t &size4) :
63 std::runtime_error(problem) {
64#ifdef WHAT
65 error_header();
66 std::cout << problem << "\n";
67 std::cout << " Two dimensional container problem \n";
68 std::cout << " Container 1 size 1 is " << size1 << "\n";
69 std::cout << " Container 1 size 2 is " << size2 << "\n";
70 std::cout << " Container 2 size 1 is " << size3 << "\n";
71 std::cout << " Container 2 size 2 is " << size4 << "\n\n";
72#endif
73
74 }
75
76 private:
77
78 void error_header() {
79 std::cout << "----------------------------------------------------\n";
80 std::cout << " Error: A CppNoddy routine has had a GEOMETRY error!\n";
81 std::cout << "----------------------------------------------------\n";
82 }
83
84 };
85
86
87 /// An exception class that is thrown if too many
88 /// Newton steps are taken in either the scalar or
89 /// vector Newton classes.
90 class ExceptionItn : public std::runtime_error {
91 public:
92 ExceptionItn(const std::string &problem, const unsigned &itns, const double &max_resid) :
93 std::runtime_error(problem) {
94#ifdef WHAT
95 error_header();
96 std::cout << problem << "\n";
97 std::cout << " The number of iterations taken so far = " << itns << "\n";
98 std::cout << " The maximum residual at this point is = " << max_resid << "\n\n";
99#endif
100
101 }
102
103 private:
104
105 void error_header() {
106 std::cout << "----------------------------------------------------\n";
107 std::cout << " Error: A CppNoddy routine has had an ITERATION error\n";
108 std::cout << "----------------------------------------------------\n";
109 }
110
111 };
112
113
114 /// An exception to indicate that a CppNoddy container
115 /// has been accessed with index/indices outside the
116 /// maximum range for the container.
117 class ExceptionRange : public std::runtime_error {
118 public:
119
120 ExceptionRange(const std::string &problem, const std::size_t &size1, const std::size_t &index1) :
121 std::runtime_error(problem) {
122#ifdef WHAT
123 error_header();
124 std::cout << problem << "\n";
125 std::cout << " Range error for one-dimensional container.\n";
126 std::cout << " Size 1 of container = " << size1 << "\n";
127 std::cout << " Index 1 being accessed = " << index1 << "\n\n";
128#endif
129
130 }
131
132 ExceptionRange(const std::string &problem, const std::size_t &size1, const std::size_t &index1,
133 const std::size_t &size2, const std::size_t &index2) :
134 std::runtime_error(problem) {
135#ifdef WHAT
136 error_header();
137 std::cout << problem << "\n";
138 std::cout << " Range error for two-dimensional container.\n";
139 std::cout << " Size 1 of container = " << size1 << "\n";
140 std::cout << " Size 2 of container = " << size2 << "\n";
141 std::cout << " Index 1 being accessed = " << index1 << "\n";
142 std::cout << " Index 2 being accessed = " << index2 << "\n\n";
143#endif
144
145 }
146 private:
147
148 void error_header() {
149 std::cout << "----------------------------------------------------\n";
150 std::cout << " Error: A CppNoddy routine has had a RANGE error! \n";
151 std::cout << "----------------------------------------------------\n";
152 }
153
154 };
155
156
157 /// A generic runtime exception
158 class ExceptionRuntime : public std::runtime_error {
159 public:
160 ExceptionRuntime(const std::string &problem) : std::runtime_error(problem) {
161#ifdef WHAT
162 error_header();
163 std::cout << problem << "\n";
164#endif
165
166 }
167
168 private:
169
170 void error_header() {
171 std::cout << "----------------------------------------------------\n";
172 std::cout << " Error: A CppNoddy routine has had a RUNTIME problem! \n";
173 std::cout << "----------------------------------------------------\n";
174 }
175
176 };
177
178 /// Not used yet....
180 public:
181 ExceptionBifurcation(const std::string &problem) {
182#ifdef WHAT
183 std::cout << problem << "\n";
184#endif
185
186 }
187
188 private:
189
190 };
191}
192
193#endif // EXCEPTIONRUNTIME_H
ExceptionBifurcation(const std::string &problem)
Definition: Exceptions.h:181
An exception to indicate that an error has been detected in an external (LAPACK) routine.
Definition: Exceptions.h:20
ExceptionExternal(const std::string &problem, const int &ifail=0)
Definition: Exceptions.h:22
An exception class to be thrown when a container of incorrect geometry used in any class/method.
Definition: Exceptions.h:47
ExceptionGeom(const std::string &problem, const std::size_t &size1, const std::size_t &size2, const std::size_t &size3, const std::size_t &size4)
Definition: Exceptions.h:61
ExceptionGeom(const std::string &problem, const std::size_t &size1, const std::size_t &size2)
Definition: Exceptions.h:49
An exception class that is thrown if too many Newton steps are taken in either the scalar or vector N...
Definition: Exceptions.h:90
ExceptionItn(const std::string &problem, const unsigned &itns, const double &max_resid)
Definition: Exceptions.h:92
An exception to indicate that a CppNoddy container has been accessed with index/indices outside the m...
Definition: Exceptions.h:117
ExceptionRange(const std::string &problem, const std::size_t &size1, const std::size_t &index1, const std::size_t &size2, const std::size_t &index2)
Definition: Exceptions.h:132
ExceptionRange(const std::string &problem, const std::size_t &size1, const std::size_t &index1)
Definition: Exceptions.h:120
A generic runtime exception.
Definition: Exceptions.h:158
ExceptionRuntime(const std::string &problem)
Definition: Exceptions.h:160
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt