1 /* Copyright 2002, The libsigc++ Development Team
2 * Assigned to public domain. Use as you wish without restriction.
5 #include "testutilities.h"
6 #include <sigc++/adaptors/exception_catch.h>
13 std::ostringstream result_stream;
15 struct f : public sigc::functor_base
17 typedef int result_type;
21 result_stream << "f(int " << i << ") ";
22 throw std::range_error("out of range ");
26 struct g : public sigc::functor_base
28 typedef int result_type;
32 result_stream << "g() ";
33 throw std::range_error("out of range ");
37 struct g_void : public sigc::functor_base
39 typedef void result_type;
43 result_stream << "g_void() ";
44 throw std::range_error("out of range ");
56 catch (const std::range_error& e) // catch what types we know
58 result_stream << "caught " << e.what();
61 // all else continues out.
65 } // end anonymous namespace
67 int main(int argc, char* argv[])
69 auto util = TestUtilities::get_instance();
71 if (!util->check_command_args(argc, argv))
72 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
74 result_stream << sigc::exception_catch(f(), my_catch())(2);
75 util->check_result(result_stream, "f(int 2) caught out of range 1");
77 result_stream << sigc::exception_catch(g(), my_catch())();
78 util->check_result(result_stream, "g() caught out of range 1");
80 sigc::exception_catch(g_void(), my_catch())(); // void test
81 util->check_result(result_stream, "g_void() caught out of range ");
83 return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;