Catch more exceptions
This commit is contained in:
parent
df4c18e47b
commit
d137b29608
|
@ -1,6 +1,7 @@
|
||||||
#ifndef AOCPP_GENERATOR_HPP_
|
#ifndef AOCPP_GENERATOR_HPP_
|
||||||
#define AOCPP_GENERATOR_HPP_
|
#define AOCPP_GENERATOR_HPP_
|
||||||
|
|
||||||
|
#include <concepts>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
{
|
{
|
||||||
return Generator{handle_type::from_promise(*this)};
|
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 {}; }
|
co::suspend_always final_suspend() noexcept { return {}; }
|
||||||
void unhandled_exception() { exception_ = std::current_exception(); }
|
void unhandled_exception() { exception_ = std::current_exception(); }
|
||||||
|
|
||||||
|
@ -50,10 +51,10 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Generator() noexcept = default;
|
Generator() noexcept = default;
|
||||||
Generator(handle_type h) : h_(h) {}
|
Generator(handle_type h) noexcept : h_(h) {}
|
||||||
Generator(Generator && g) : h_{g.h_} { g.h_ = nullptr; };
|
Generator(Generator && g) noexcept : h_{std::move(g.h_)} { g.h_ = nullptr; };
|
||||||
Generator(Generator const& g) = delete;
|
|
||||||
Generator & operator=(Generator && rhs) = delete;
|
Generator & operator=(Generator && rhs) = delete;
|
||||||
|
Generator(Generator const& g) = delete;
|
||||||
Generator & operator=(Generator const& rhs) = delete;
|
Generator & operator=(Generator const& rhs) = delete;
|
||||||
~Generator() { if (h_) h_.destroy(); }
|
~Generator() { if (h_) h_.destroy(); }
|
||||||
std::optional<T> operator()()
|
std::optional<T> operator()()
|
||||||
|
|
|
@ -95,31 +95,47 @@ auto main(int argc, char **argv) -> int
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.run_tests)
|
if (options.run_tests)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return doctest::Context{argc, argv}.run();
|
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::ifstream fin;
|
||||||
std::ofstream fout;
|
std::ofstream fout;
|
||||||
std::istream &in{options.in_name ? fin = std::ifstream{options.in_name} : std::cin};
|
std::istream *in;
|
||||||
std::ostream &out{options.out_name ? fout = std::ofstream{options.out_name} : std::cout};
|
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;
|
std::cerr << "Bad input file" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out.fail())
|
if (out->fail()) {
|
||||||
{
|
|
||||||
std::cerr << "Bad output file" << std::endl;
|
std::cerr << "Bad output file" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Main(in, out);
|
Main(*in, *out);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
catch (std::exception const &e)
|
catch (std::exception const &e)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user