libMesh
libmesh_exceptions.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_LIBMESH_EXCEPTIONS_H
21 #define LIBMESH_LIBMESH_EXCEPTIONS_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_ENABLE_EXCEPTIONS
26 #include <stdexcept>
27 #include <string>
28 #include <sstream>
29 
30 #ifdef LIBMESH_HAVE_CXX11_NOEXCEPT
31 #define libmesh_noexcept noexcept
32 #else
33 #define libmesh_noexcept throw()
34 #endif
35 
36 namespace libMesh {
37 
42 class LogicError : public std::logic_error
43 {
44 public:
45  LogicError() : std::logic_error( "Error in libMesh internal logic" ) {}
46  LogicError(const std::string & msg) : std::logic_error( msg ) {}
47 };
48 
49 
55 class NotImplemented : public std::logic_error
56 {
57 public:
58  NotImplemented() : std::logic_error( "Error: not implemented!" ) {}
59 };
60 
61 
69 class FileError : public std::runtime_error
70 {
71 public:
72  FileError(const std::string & filename) : std::runtime_error( "Error accessing file: " + filename ) {}
73 };
74 
75 
83 class ConvergenceFailure : public std::runtime_error
84 {
85 public:
86  ConvergenceFailure() : std::runtime_error( "Unrecoverable failure to converge" ) {}
87 };
88 
89 
93 class DynamicCastFailure: public std::runtime_error
94 {
95 public:
96  DynamicCastFailure() : std::runtime_error( "Failed dynamic cast!" ) {}
97 };
98 
102 class FloatingPointException: public std::runtime_error
103 {
104 public:
105  FloatingPointException() : std::runtime_error( "libmesh FPE!" ) {}
106 };
107 
111 class SolverException: public std::exception
112 {
113 public:
114  SolverException(int error_code_in) :
115  std::exception(),
116  error_code(error_code_in)
117  {
118  std::ostringstream oss;
119  oss << "Error code " << error_code << " during solve." << std::endl;
120  what_message = oss.str();
121  }
122 
126  virtual ~SolverException() libmesh_noexcept {};
127 
131  virtual const char * what() const libmesh_noexcept
132  {
133  // std::string::c_str() is noexcept in C++11, so it's safe to call
134  // in what() because it can't throw.
135  return what_message.c_str();
136  }
137 
142 
146  std::string what_message;
147 };
148 
149 }
150 
151 #define LIBMESH_THROW(e) do { throw e; } while (0)
152 #define libmesh_try try
153 #define libmesh_catch(e) catch(e)
154 
155 #else
156 
157 #define LIBMESH_THROW(e) do { std::abort(); } while (0)
158 #define libmesh_try
159 #define libmesh_catch(e) if (0)
160 
161 #endif // LIBMESH_ENABLE_EXCEPTIONS
162 
163 #endif // LIBMESH_LIBMESH_EXCEPTIONS_H
A class to stub for features that should be in libMesh, but haven&#39;t been written yet, to be thrown by "libmesh_not_implemented();".
A class representing that a dynamic cast failed to produce expected output.
virtual ~SolverException() libmesh_noexcept
Virtual destructor, gotta have one of those.
virtual const char * what() const libmesh_noexcept
Override the what() function to provide a generic error message.
SolverException(int error_code_in)
FileError(const std::string &filename)
int error_code
The error code generated by the solver.
A class representing a floating point exception.
The libMesh namespace provides an interface to certain functionality in the library.
std::string what_message
string which holds the message built in the constructor.
A class representing an exception during a solve.
LogicError(const std::string &msg)
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
A class representing a solver&#39;s failure to converge, to be thrown by "libmesh_convergence_failure();"...
A class representing a failed attempt by the library to open a file (or construct an fstream...