Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ endif()
# Always looking for stacktrace can cause problems when cross compiling
# Hence, avoid finding boost if user didn't ask for it.
option (EKAT_ENABLE_BOOST_STACKTRACE "Whether to enable Boost stacktrace" OFF)

if (EKAT_ENABLE_BOOST_STACKTRACE)
message (STATUS "Looking for boost::stacktrace ...")
# Stacktrace is available with Boost>=1.65
Expand Down Expand Up @@ -77,7 +78,7 @@ endif()

if (EKAT_HAS_STACKTRACE)
target_link_libraries(ekat_core PUBLIC ${Boost_LIBRARIES})
target_compile_definitions(ekat_core PRIVATE EKAT_HAS_STACKTRACE)
target_compile_definitions(ekat_core PRIVATE EKAT_HAS_STACKTRACE BOOST_STACKTRACE_USE_ADDR2LINE)
endif()

if (EKAT_DEFAULT_BFB)
Expand Down
22 changes: 12 additions & 10 deletions src/core/ekat_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,30 @@ void throw_exception(const std::string& msg)
if constexpr (std::is_constructible<exception_type, const std::string&>::value) {
throw exception_type(msg);
} else if constexpr (std::is_default_constructible<exception_type>::value) {
std::cerr << msg;
std::cerr << msg << "\n";
throw exception_type();
} else {
std::cerr << msg << "\n";
std::cerr << "Cannot create exception of type\n";
std::cerr << " " << typeid(exception_type).name() << "\n";
std::cerr << "The program will terminate\n";
std::cerr << "Throwing std::runtime_error instead...\n";
throw std::runtime_error(msg);
}
}

} // namespace ekat

// Internal do not call directly.
#define IMPL_THROW(condition, msg, exception_type) \
do { \
if ( ! (condition) ) { \
std::stringstream _ss_; \
_ss_ << "\n FAIL:\n" << #condition << "\n"; \
_ss_ << EKAT_BACKTRACE; \
_ss_ << "\n" << msg; \
ekat::throw_exception<exception_type>(_ss_.str()); \
} \
do { \
if ( ! (condition) ) { \
std::cerr << "\nFAILED CONDITION: '" << #condition << "'\n\n"; \
std::cerr << "BACKTRACE:\n"; \
std::cerr << EKAT_BACKTRACE << "\n"; \
std::stringstream ss; \
ss << msg; \
ekat::throw_exception<exception_type>(ss.str()); \
} \
} while(0)

// Define the EKAT_REQUIRE macros for different argument counts
Expand Down