Catch more exceptions
This commit is contained in:
@@ -96,30 +96,46 @@ auto main(int argc, char **argv) -> int
|
||||
|
||||
if (options.run_tests)
|
||||
{
|
||||
return doctest::Context{argc, argv}.run();
|
||||
try
|
||||
{
|
||||
return doctest::Context{argc, argv}.run();
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
std::cerr << "Test suite failed: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Establish input streams
|
||||
std::ifstream fin;
|
||||
std::ofstream fout;
|
||||
std::istream &in{options.in_name ? fin = std::ifstream{options.in_name} : std::cin};
|
||||
std::ostream &out{options.out_name ? fout = std::ofstream{options.out_name} : std::cout};
|
||||
std::istream *in;
|
||||
std::ostream *out;
|
||||
|
||||
if (in.fail())
|
||||
try
|
||||
{
|
||||
in = &(options.in_name ? fin = std::ifstream{options.in_name} : std::cin);
|
||||
out = &(options.out_name ? fout = std::ofstream{options.out_name} : std::cout);
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
std::cerr << "IO setup failed: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (in->fail()) {
|
||||
std::cerr << "Bad input file" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (out.fail())
|
||||
{
|
||||
if (out->fail()) {
|
||||
std::cerr << "Bad output file" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Main(in, out);
|
||||
Main(*in, *out);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
|
Reference in New Issue
Block a user