VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
UbException.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef UBEXCEPTION_H
35#define UBEXCEPTION_H
36
37#include <iostream>
38#include <sstream>
39#include <stdexcept>
40#include <string>
41#include <vector>
42
43#include "./UbTuple.h"
44
45//=========================================================================
46//
52//
53//=========================================================================
54
55// Macro UB_FUNCTION: figures out the method/function name (platform dependant)
56#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600))
57#define UB_FUNCTION __PRETTY_FUNCTION__
58#elif defined(__DMC__) && (__DMC__ >= 0x810)
59#define UB_FUNCTION __PRETTY_FUNCTION__
60#elif defined(__FUNCSIG__)
61#define UB_FUNCTION __FUNCSIG__
62#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
63#define UB_FUNCTION __FUNCTION__
64#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
65#define UB_FUNCTION __FUNC__
66#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
67#define UB_FUNCTION __func__
68#else
69#define UB_FUNCTION "(unknown)"
70#endif
71
72// Helper Marco
73#define UB_EXARGS __FILE__, __LINE__, UB_FUNCTION
74
75#ifdef CAB_BOOST
76#define UB_THROW(e) throw boost::enable_current_exception(e)
77#else
78#define UB_THROW(e) throw e
79#endif
80
81class UbException : public std::runtime_error
82{
83public:
85
86public:
88 // constructors
89 UbException() : std::runtime_error("") {}
90 /*==========================================================*/
91 UbException(const std::string &str) : std::runtime_error("") { this->addInfo(str); }
92 /*==========================================================*/
93 UbException(const std::string &file, const int &line, const std::string &err_str) : std::runtime_error("")
94 {
95 this->addInfo(file, line, "unknown", err_str);
96 }
97 /*==========================================================*/
98 // UbException(const char* file, const int& line, const char* function, const std::string& err_str)
99 UbException(const std::string &file, const int &line, const std::string &function, const std::string &err_str)
100 : std::runtime_error("")
101 {
102 this->addInfo(file, line, function, err_str);
103 }
105 // destructor
108 // virtual public methods
109 // returns exception-string
110 const char *what() const noexcept override
111 {
112 exceptionString = this->toString();
113 return exceptionString.c_str(); // ansonsten ist das Verhalten anschliessend undefiniert!
114 }
115 /*==========================================================*/
116 virtual void addInfo(const std::string &err_str)
117 {
118 exceptionData.push_back(makeUbTuple(std::string("-"), 0, std::string("unknown"), err_str));
119 }
120 /*==========================================================*/
121 // add exception
122 virtual void addInfo(const std::string &file, const int &line, const std::string &function,
123 const std::string &err_str)
124 {
125 exceptionData.push_back(makeUbTuple(file, line, function, err_str));
126 }
127 /*==========================================================*/
128 // returns exception-string with all calles exceptions
129 virtual const std::vector<std::string> getInfo() const
130 {
131 std::vector<std::string> tmp;
132 for (std::size_t i = 0; i < exceptionData.size(); i++) {
133 std::stringstream str;
135 << ", " << val<4>(exceptionData[i]);
136 tmp.push_back(str.str());
137 }
138 return tmp;
139 }
140 /*==========================================================*/
141 // returns exception-string with all calles exceptions and detailes informations
142 virtual std::string toString() const
143 {
144 std::stringstream str("UbExeption");
145
146 for (std::size_t i = 0; i < exceptionData.size(); i++)
147 str << (std::string) "caller[" << i << "]\n"
148 << " - file: " << val<1>(exceptionData[i]) << "\n"
149 << " - line: " << val<2>(exceptionData[i]) << "\n"
150 << " - function: " << val<3>(exceptionData[i]) << "\n"
151 << " - what: " << val<4>(exceptionData[i]) << std::endl;
152
153 return str.str();
154 }
155
156protected:
158 // protected member
159 std::vector<ExceptionData> exceptionData;
160 mutable std::string exceptionString;
161};
162
163// overlading operator <<
164inline std::ostream &operator<<(std::ostream &os, const UbException &e) { return os << e.toString(); }
165
166#endif // UBEXCEPTION_H
167
virtual void addInfo(const std::string &err_str)
~UbException() noexcept override=default
UbException(const std::string &file, const int &line, const std::string &function, const std::string &err_str)
Definition UbException.h:99
std::string exceptionString
std::vector< ExceptionData > exceptionData
virtual const std::vector< std::string > getInfo() const
virtual std::string toString() const
const char * what() const noexcept override
UbException(const std::string &file, const int &line, const std::string &err_str)
Definition UbException.h:93
UbTuple< std::string, int, std::string, std::string > ExceptionData
Definition UbException.h:84
virtual void addInfo(const std::string &file, const int &line, const std::string &function, const std::string &err_str)
UbException(const std::string &str)
Definition UbException.h:91
std::shared_ptr< T > SPtr
std::ostream & operator<<(std::ostream &os, const UbException &e)
UbTuple< T1 > makeUbTuple(T1 const &a1)
Definition UbTuple.h:542