OGS 6.1.0-1721-g6382411ad
Error.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #ifdef OGS_FATAL_ABORT
13 
14 #include <cstdlib>
15 #include <logog/include/logog.hpp>
16 
17 namespace BaseLib
18 {
19 namespace detail
20 {
21 template <typename Msg>
22 #if defined(_MSC_VER) && _MSC_VER < 1500
23 __declspec(noreturn)
24 #else
25 [[noreturn]]
26 #endif
27  bool error_impl(Msg&& msg)
28 {
29  ERR("%s", msg.data());
30  std::abort();
31 }
32 
33 } // namespace detail
34 
35 } // namespace BaseLib
36 
37 #else // OGS_FATAL_ABORT
38 
39 #include <stdexcept>
40 
41 namespace BaseLib
42 {
43 namespace detail
44 {
45 template <typename Msg>
46 #if defined(_MSC_VER) && _MSC_VER < 1500
47 __declspec(noreturn)
48 #else
49 [[noreturn]]
50 #endif
51  bool error_impl(Msg&& msg)
52 {
53  throw std::runtime_error(std::forward<Msg>(msg));
54 }
55 
56 } // namespace detail
57 
58 } // namespace BaseLib
59 
60 #endif // OGS_FATAL_ABORT
61 
62 #include "FileTools.h"
63 #include "StringTools.h"
64 
65 #define OGS_STR(x) #x
66 #define OGS_STRINGIFY(x) OGS_STR(x)
67 #define OGS_LOCATION \
68  " at " + BaseLib::extractBaseName(__FILE__) + \
69  ", line " OGS_STRINGIFY(__LINE__)
70 
71 #define OGS_FATAL(fmt, ...) \
72  BaseLib::detail::error_impl(BaseLib::format(fmt, ##__VA_ARGS__) + \
73  OGS_LOCATION)
Definition of string helper functions.
bool error_impl(Msg &&msg)
Definition: Error.h:51
Build information.
Filename manipulation routines.