bin: factor exception-handling code

* bin/common_setup.cc, bin/common_setup.hh: Define a protected_main()
function that deal with exceptions.
* bin/autcross.cc, bin/autfilt.cc, bin/dstar2tgba.cc, bin/genaut.cc,
bin/genltl.cc, bin/ltl2tgba.cc, bin/ltl2tgta.cc, bin/ltlcross.cc,
bin/ltldo.cc, bin/ltlfilt.cc, bin/ltlgrind.cc, bin/ltlsynt.cc,
bin/randaut.cc, bin/randltl.cc: Use it for all tools.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-16 18:35:59 +02:00
parent fc0ed01a45
commit 645bb55622
16 changed files with 328 additions and 386 deletions

View file

@ -169,3 +169,23 @@ const struct argp misc_argp = { options, parse_opt_misc,
const struct argp misc_argp_hidden = { options_hidden, parse_opt_misc,
nullptr, nullptr, nullptr,
nullptr, nullptr };
int protected_main(char** progname, std::function<int()> mainfun)
{
try
{
setup(progname);
return mainfun();
}
catch (const std::runtime_error& e)
{
error(2, 0, "%s", e.what());
}
catch (const std::invalid_argument& e)
{
error(2, 0, "%s", e.what());
}
SPOT_UNREACHABLE();
return 2;
}