Skip to content

Commit 423ca92

Browse files
committed
use try/catch to delete dump on dump_modify error and then rethrow exception
1 parent 332157f commit 423ca92

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/write_dump.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ void WriteDump::command(int narg, char **arg)
5757
dumpargs[2] = arg[1]; // dump style
5858
dumpargs[3] = utils::strdup(std::to_string(dumpfreq)); // dump frequency
5959

60-
// delete existing dump with same ID to avoid re-use of dump-ID error
61-
62-
auto *dump = output->get_dump_by_id(dump_id);
63-
if (dump) output->delete_dump(dump_id);
64-
6560
for (int i = 2; i < modindex; ++i) dumpargs[i + 2] = arg[i];
6661

67-
dump = output->add_dump(modindex + 2, dumpargs);
68-
if (modindex < narg) dump->modify_params(narg - modindex - 1, &arg[modindex + 1]);
62+
auto *dump = output->add_dump(modindex + 2, dumpargs);
63+
64+
try {
65+
if (modindex < narg) dump->modify_params(narg - modindex - 1, &arg[modindex + 1]);
66+
} catch (LAMMPSException &e) {
67+
// delete dump after error and then rethrow the exception to avoid re-use of dump-ID error
68+
dump = output->get_dump_by_id(dump_id);
69+
if (dump) output->delete_dump(dump_id);
70+
throw e;
71+
}
6972

7073
// write out one frame and then delete the dump again
7174
// set multifile_override for DumpImage so that filename needs no "*"

0 commit comments

Comments
 (0)