Skip to content

Commit 14b5f48

Browse files
committed
Printing backtrace to cerr rather than passing it to exception ctor
Prints the bactrace without line truncation
1 parent 72d98d7 commit 14b5f48

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/core/ekat_assert.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,30 @@ void throw_exception(const std::string& msg)
3333
if constexpr (std::is_constructible<exception_type, const std::string&>::value) {
3434
throw exception_type(msg);
3535
} else if constexpr (std::is_default_constructible<exception_type>::value) {
36-
std::cerr << msg;
36+
std::cerr << msg << "\n";
3737
throw exception_type();
3838
} else {
3939
std::cerr << msg << "\n";
4040
std::cerr << "Cannot create exception of type\n";
4141
std::cerr << " " << typeid(exception_type).name() << "\n";
42-
std::cerr << "The program will terminate\n";
42+
std::cerr << "Throwing std::runtime_error instead...\n";
43+
throw std::runtime_error(msg);
4344
}
4445
}
4546

4647
} // namespace ekat
4748

4849
// Internal do not call directly.
4950
#define IMPL_THROW(condition, msg, exception_type) \
50-
do { \
51-
if ( ! (condition) ) { \
52-
std::stringstream _ss_; \
53-
_ss_ << "\n FAIL:\n" << #condition << "\n"; \
54-
_ss_ << EKAT_BACKTRACE; \
55-
_ss_ << "\n" << msg; \
56-
ekat::throw_exception<exception_type>(_ss_.str()); \
57-
} \
51+
do { \
52+
if ( ! (condition) ) { \
53+
std::cerr << "\nFAILED CONDITION: '" << #condition << "'\n\n"; \
54+
std::cerr << "BACKTRACE:\n"; \
55+
std::cerr << EKAT_BACKTRACE << "\n"; \
56+
std::stringstream ss; \
57+
ss << msg; \
58+
ekat::throw_exception<exception_type>(ss.str()); \
59+
} \
5860
} while(0)
5961

6062
// Define the EKAT_REQUIRE macros for different argument counts

0 commit comments

Comments
 (0)