From 10e3595b5798e42bcace44a7d6197410bbbde4fe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 3 Jul 2024 22:20:06 -0400 Subject: [PATCH] separately catch exceptions thrown by new --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index caf1d4d53c..da80d66b52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include #include +#include #if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE) #include @@ -89,6 +90,11 @@ int main(int argc, char **argv) finalize(); MPI_Abort(MPI_COMM_WORLD, 1); exit(1); + } catch (std::bad_alloc &ae) { + fprintf(stderr, "C++ memory allocation failed: %s\n", ae.what()); + finalize(); + MPI_Abort(MPI_COMM_WORLD, 1); + exit(1); } catch (std::exception &e) { fprintf(stderr, "Exception: %s\n", e.what()); finalize();