opm-grid
ErrorMacros.hpp
1 /*
2  Copyright 2026 Equinor ASA.
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 #ifndef OPM_GRID_ERROR_MACROS_HPP
20 #define OPM_GRID_ERROR_MACROS_HPP
21 
22 #if HAVE_OPM_COMMON
23 #include <opm/common/ErrorMacros.hpp>
24 #else
25 
26 #include <iostream>
27 #include <string>
28 
29 #define OPM_THROW(Exception, message) \
30  do { \
31  std::string oss_ = std::string{"["} + __FILE__ + ":" + \
32  std::to_string(__LINE__) + "] " + \
33  message; \
34  throw Exception(oss_); \
35  } while (false)
36 
37 #define OPM_THROW_NOLOG OPM_THROW
38 
39 // throw an exception if a condition is true
40 #define OPM_ERROR_IF(condition, message) do {if(condition){ OPM_THROW(std::logic_error, message);}} while(false)
41 
42 #define OPM_MESSAGE(x) do { std::cerr << x << std::endl; } while(false)
43 
44 #endif
45 
46 #endif // OPM_GRID_ERROR_MACROS_HPP