try to catch format errors from fmtlib

This commit is contained in:
Axel Kohlmeyer
2021-02-26 14:08:38 -05:00
parent bb13ce4349
commit 3042e28297
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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);