separately catch exceptions thrown by new

This commit is contained in:
Axel Kohlmeyer
2024-07-03 22:20:06 -04:00
parent a4d69878fa
commit 10e3595b57

View File

@ -19,6 +19,7 @@
#include <cstdlib>
#include <mpi.h>
#include <new>
#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
#include <fenv.h>
@ -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();