diff --git a/src/error.cpp b/src/error.cpp index 1ce9a0f3fe..0cbfa4c4a1 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -52,8 +52,11 @@ Error::Error(LAMMPS *lmp) : Pointers(lmp) { void Error::universe_all(const std::string &file, int line, const std::string &str) { MPI_Barrier(universe->uworld); - std::string mesg = fmt::format("ERROR: {} ({}:{})\n", - str,truncpath(file),line); + std::string mesg = "ERROR: " + str; + try { + mesg += fmt::format(" ({}:{})\n",truncpath(file),line); + } catch (fmt::format_error &e) { + } if (universe->me == 0) { if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen); if (universe->ulogfile) fputs(mesg.c_str(),universe->ulogfile); @@ -135,9 +138,14 @@ void Error::all(const std::string &file, int line, const std::string &str) MPI_Comm_rank(world,&me); if (me == 0) { + std::string mesg = "ERROR: " + str; if (input && input->line) lastcmd = input->line; - utils::logmesg(lmp,fmt::format("ERROR: {} ({}:{})\nLast command: {}\n", - str,truncpath(file),line,lastcmd)); + try { + mesg += fmt::format(" ({}:{})\nLast command: {}\n", + truncpath(file),line,lastcmd); + } catch (fmt::format_error &e) { + } + utils::logmesg(lmp,mesg); } #ifdef LAMMPS_EXCEPTIONS diff --git a/src/main.cpp b/src/main.cpp index 582de6999c..8e8e1ee3b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,10 @@ int main(int argc, char **argv) MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); exit(1); + } catch(fmt::format_error &fe) { + fprintf(stderr,"fmt::format_error: %s\n", fe.what()); + MPI_Abort(MPI_COMM_WORLD, 1); + exit(1); } #else LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD);