OOFEM 3.0
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35// ************************************
36// *** Error macros ***
37// ************************************
38
39#ifndef error_h
40#define error_h
41
42#include "logger.h"
43
44#include <string>
45#include <cstdio>
46#include <cstdlib>
47#include <stdexcept>
48
49
50namespace oofem {
52#define OOFEM_EXIT(code) \
53 oofem_logger.printStatistics(); \
54 fprintf(stderr, "oofem exit code %d\n", code); \
55 exit(code);
56
57
58class OOFEM_EXPORT RuntimeException : public std::exception
59{
60public:
61 std::string msg;
62
63 RuntimeException(const char* _func, const char* _file, int _line, const char *format, ...)
64 #if defined(__GNUC__) || defined (__clang)
65 __attribute__((format(printf, 5, 6)))
66 #endif
67 ;
68 const char* what() const noexcept override;
69};
70
72
78#define OOFEM_FATAL(...) { throw RuntimeException(__func__, __FILE__, __LINE__, __VA_ARGS__);}
79#define OOFEM_ERROR(...) { throw RuntimeException(__func__, __FILE__, __LINE__, __VA_ARGS__);}
80#define OOFEM_WARNING(...) { if(warningIsError){ oofem_logger.writeELogMsg(Logger::LOG_LEVEL_WARNING,errorInfo(__func__).c_str(), __FILE__, __LINE__,"Promoting warning to error."); OOFEM_ERROR(__VA_ARGS__); } oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_WARNING, errorInfo(__func__).c_str(), __FILE__, __LINE__, __VA_ARGS__); }
81#define OOFEM_SERROR(...) { oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_ERROR, __func__, __FILE__, __LINE__, __VA_ARGS__); OOFEM_EXIT(1); }
82#define OOFEM_SWARNING(...) oofem_logger.writeELogMsg(Logger :: LOG_LEVEL_WARNING, __func__, __FILE__, __LINE__, __VA_ARGS__)
84
85OOFEM_EXPORT std::string errorInfo(const char *func);
86
87} // end namespace oofem
88#endif // error_h
RuntimeException(const char *_func, const char *_file, int _line, const char *format,...)
Definition error.C:52
std::string msg
Definition error.h:61
const char * what() const noexcept override
Definition error.C:65
bool warningIsError
Definition error.C:45
#define OOFEM_EXPORT
Definition oofemcfg.h:7

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011