ErrorGuard.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Joakim Hove/datagr
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef ERROR_GUARD_HPP
22#define ERROR_GUARD_HPP
23
24#include <string>
25#include <vector>
26
27namespace Opm {
28
30public:
31 void addError(const std::string& errorKey, const std::string& msg);
32 void addWarning(const std::string& errorKey, const std::string &msg);
33 void clear();
34
35 explicit operator bool() const { return !this->error_list.empty(); }
36
37 /*
38 Observe that this desctructor has a somewhat special semantics. If there
39 are errors in the error list it will print all warnings and errors on
40 stderr and throw std::runtime_error.
41 */
43 void terminate() const;
44 void dump() const;
45
46private:
47
48 std::vector<std::pair<std::string, std::string>> error_list;
49 std::vector<std::pair<std::string, std::string>> warning_list;
50};
51
52}
53
54#endif
const char *const string
Definition: cJSON.h:170
Definition: ErrorGuard.hpp:29
void terminate() const
void dump() const
void addWarning(const std::string &errorKey, const std::string &msg)
void addError(const std::string &errorKey, const std::string &msg)
char bool
Definition: msvc_stdbool.h:17
Definition: A.hpp:4