KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
exception.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 #if !defined(KRATOS_EXCEPTION_H_INCLUDED )
15 #define KRATOS_EXCEPTION_H_INCLUDED
16 
17 // System includes
18 #include <stdexcept>
19 #include <string>
20 #include <iostream>
21 #include <sstream>
22 #include <vector>
23 
24 // External includes
25 
26 // Project includes
28 #include "includes/code_location.h"
30 
31 namespace Kratos
32 {
35 
38 
47 class KRATOS_API(KRATOS_CORE) Exception
48  : public std::exception
49 {
50 public:
53 
57 
59  Exception();
60 
61  explicit Exception(const std::string& rWhat );
62 
63  Exception(const std::string& rWhat, const CodeLocation& Location);
64 
66  Exception(Exception const& Other);
67 
69  ~Exception() noexcept override;
70 
71 
75 
77  Exception& operator=(Exception const& rOther) = delete;
78 
80  Exception& operator << (CodeLocation const& TheLocation);
81 
83  template<class StreamValueType>
84  Exception& operator << (StreamValueType const& rValue)
85  {
86  std::stringstream buffer;
87  buffer << rValue;
88 
89  append_message(buffer.str());
90 
91  return *this;
92  }
93 
95  Exception& operator << (std::ostream& (*pf)(std::ostream&));
97  Exception& operator << (const char * rString);
98 
102 
103  void append_message(std::string const& rMessage);
104 
105  void add_to_call_stack(CodeLocation const& TheLocation);
106 
107 
111 
113 
116  const char* what() const noexcept override;
117 
118  const std::string& message() const;
119 
120  const CodeLocation where() const;
121 
125 
127  virtual std::string Info() const;
128 
130  virtual void PrintInfo(std::ostream& rOStream) const;
131 
133  virtual void PrintData(std::ostream& rOStream) const;
134 
135 
137 
138 private:
141 
142  std::string mMessage;
143  std::string mWhat;
144  std::vector<CodeLocation> mCallStack;
145 
149 
150  void update_what();
151 
153 
154 }; // Class Exception
155 
157 
160 
161 #define KRATOS_ERROR throw Kratos::Exception("Error: ", KRATOS_CODE_LOCATION)
162 #define KRATOS_ERROR_IF(conditional) if(conditional) KRATOS_ERROR
163 #define KRATOS_ERROR_IF_NOT(conditional) if(!(conditional)) KRATOS_ERROR
164 
165 #ifdef KRATOS_DEBUG
166 #define KRATOS_DEBUG_ERROR KRATOS_ERROR
167 #define KRATOS_DEBUG_ERROR_IF(conditional) KRATOS_ERROR_IF(conditional)
168 #define KRATOS_DEBUG_ERROR_IF_NOT(conditional) KRATOS_ERROR_IF_NOT(conditional)
169 #else
170 #define KRATOS_DEBUG_ERROR if(false) KRATOS_ERROR
171 #define KRATOS_DEBUG_ERROR_IF(conditional) if(false) KRATOS_ERROR_IF(conditional)
172 #define KRATOS_DEBUG_ERROR_IF_NOT(conditional) if(false) KRATOS_ERROR_IF_NOT(conditional)
173 #endif
177 
178 
180 std::istream& operator >> (std::istream& rIStream,
181  Exception& rThis);
182 
184 KRATOS_API(KRATOS_CORE) std::ostream& operator << (std::ostream& rOStream, const Exception& rThis);
185 
186 
188 
190 
191 } // namespace Kratos.
192 
193 #endif // KRATOS_EXCEPTION_H_INCLUDED defined
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition: code_location.h:31
Extends the std::exception class with more information about error location.
Definition: exception.h:49
Exception & operator=(Exception const &rOther)=delete
Assignment operator is deleted.
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
tuple const
Definition: ode_solve.py:403
namespace
Definition: array_1d.h:793