From 09ed8e69312cebe31b69af4f42a3b0417774cf04 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 24 Jun 2011 15:22:55 -0700 Subject: uhd: added dynamic throw and clone to exceptions --- host/tests/error_test.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'host/tests/error_test.cpp') diff --git a/host/tests/error_test.cpp b/host/tests/error_test.cpp index 983f0150c..69437e732 100644 --- a/host/tests/error_test.cpp +++ b/host/tests/error_test.cpp @@ -44,7 +44,8 @@ BOOST_AUTO_TEST_CASE(test_assert_has){ std::cout << "The output of the assert_has error:" << std::endl; try{ uhd::assert_has(vec, 1, "prime"); - }catch(const std::exception &e){ + } + catch(const std::exception &e){ std::cout << e.what() << std::endl; } } @@ -53,7 +54,37 @@ BOOST_AUTO_TEST_CASE(test_assert_throw){ std::cout << "The output of the assert throw error:" << std::endl; try{ UHD_ASSERT_THROW(2 + 2 == 5); - }catch(const std::exception &e){ + } + catch(const std::exception &e){ + std::cout << e.what() << std::endl; + } +} + +BOOST_AUTO_TEST_CASE(test_exception_dynamic){ + uhd::exception *exception_clone; + + //throw an exception and dynamically clone it + try{ + throw uhd::runtime_error("noooooo"); + } + catch(const uhd::exception &e){ std::cout << e.what() << std::endl; + exception_clone = e.dynamic_clone(); + } + + //now we dynamically re-throw the exception + try{ + exception_clone->dynamic_throw(); + } + catch(const uhd::assertion_error &e){ + BOOST_CHECK(false); } + catch(const uhd::runtime_error &e){ + BOOST_CHECK(true); + } + catch(const uhd::exception &e){ + BOOST_CHECK(false); + } + + delete exception_clone; //manual cleanup } -- cgit v1.2.3 From d4ca69984701bda2299186140c7b551f19f9b550 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 24 Jun 2011 16:09:22 -0700 Subject: uhd: print the exception so e gets used (avoid MSVC warning) --- host/tests/error_test.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'host/tests/error_test.cpp') diff --git a/host/tests/error_test.cpp b/host/tests/error_test.cpp index 69437e732..3d784b1f7 100644 --- a/host/tests/error_test.cpp +++ b/host/tests/error_test.cpp @@ -77,12 +77,15 @@ BOOST_AUTO_TEST_CASE(test_exception_dynamic){ exception_clone->dynamic_throw(); } catch(const uhd::assertion_error &e){ + std::cout << e.what() << std::endl; BOOST_CHECK(false); } catch(const uhd::runtime_error &e){ + std::cout << e.what() << std::endl; BOOST_CHECK(true); } catch(const uhd::exception &e){ + std::cout << e.what() << std::endl; BOOST_CHECK(false); } -- cgit v1.2.3