diff --git a/BaseLib/Error.h b/BaseLib/Error.h index f2894fd2066b21dcc079d053abce7c590bed2421..a982ae4efefadb748cdae1cf69e40f9ff5fc2735 100644 --- a/BaseLib/Error.h +++ b/BaseLib/Error.h @@ -10,15 +10,31 @@ #ifndef BASELIB_ERROR_H #define BASELIB_ERROR_H -#include <stdexcept> +#ifdef OGS_FATAL_ABORT +#include <cstdlib> +#include <logog/include/logog.hpp> #include "StringTools.h" + +#define OGS_FATAL(fmt, ...)\ + {\ + ERR("%s", BaseLib::format(fmt, ##__VA_ARGS__).data());\ + std::abort();\ + } + +#else // OGS_FATAL_ABORT + +#include <stdexcept> #include "FileTools.h" +#include "StringTools.h" #define OGS_STR(x) #x #define OGS_STRINGIFY(x) OGS_STR(x) #define OGS_LOCATION " at " + BaseLib::extractBaseName(__FILE__) + ", line " OGS_STRINGIFY(__LINE__) + #define OGS_FATAL(fmt, ...)\ throw std::runtime_error(BaseLib::format(fmt, ##__VA_ARGS__) + OGS_LOCATION); +#endif // OGS_FATAL_ABORT + #endif //BASELIB_ERROR_H diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b9149bd088da5f5d6e85fe21833cb86d109331a..12e691385c4ba7708d5bc933c187027d186b20e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,9 @@ option(EIGEN_NO_DEBUG "Disables Eigen's assertions" OFF) # Logging option(OGS_DISABLE_LOGGING "Disables all logog messages." OFF) +# Debug +option(OGS_FATAL_ABORT "Abort in OGS_FATAL" OFF) + # Compiler flags set(OGS_CXX_FLAGS "" CACHE STRING "Additional C++ compiler flags.") option(STL_NO_DEBUG "Disable STL debug in debug build" OFF) @@ -154,6 +157,10 @@ if(OGS_USE_EIGEN) add_definitions(-DOGS_USE_EIGEN) endif() +if (OGS_FATAL_ABORT) + add_definitions(-DOGS_FATAL_ABORT) +endif() + if(OGS_BUILD_TESTS) set(Data_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Tests/Data CACHE INTERNAL "") set(Data_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Tests/Data CACHE INTERNAL "")