Catch more exceptions
This commit is contained in:
parent
df4c18e47b
commit
d137b29608
|
@ -1,6 +1,7 @@
|
|||
#ifndef AOCPP_GENERATOR_HPP_
|
||||
#define AOCPP_GENERATOR_HPP_
|
||||
|
||||
#include <concepts>
|
||||
#include <exception>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
{
|
||||
return Generator{handle_type::from_promise(*this)};
|
||||
}
|
||||
co::suspend_always initial_suspend() { return {}; }
|
||||
co::suspend_always initial_suspend() noexcept { return {}; }
|
||||
co::suspend_always final_suspend() noexcept { return {}; }
|
||||
void unhandled_exception() { exception_ = std::current_exception(); }
|
||||
|
||||
|
@ -50,10 +51,10 @@ public:
|
|||
|
||||
public:
|
||||
Generator() noexcept = default;
|
||||
Generator(handle_type h) : h_(h) {}
|
||||
Generator(Generator && g) : h_{g.h_} { g.h_ = nullptr; };
|
||||
Generator(Generator const& g) = delete;
|
||||
Generator(handle_type h) noexcept : h_(h) {}
|
||||
Generator(Generator && g) noexcept : h_{std::move(g.h_)} { g.h_ = nullptr; };
|
||||
Generator & operator=(Generator && rhs) = delete;
|
||||
Generator(Generator const& g) = delete;
|
||||
Generator & operator=(Generator const& rhs) = delete;
|
||||
~Generator() { if (h_) h_.destroy(); }
|
||||
std::optional<T> operator()()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user