/Src/Dependencies/Boost/libs/phoenix/test/statement/exceptions.cpp

http://hadesmem.googlecode.com/ · C++ · 106 lines · 81 code · 18 blank · 7 comment · 2 complexity · 44f314a06784c575a8f8205db2b7d28f MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2005-2007 Dan Marsden
  3. Copyright (c) 2005-2007 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #include <stdexcept>
  8. #include <string>
  9. #include <boost/phoenix/core.hpp>
  10. #include <boost/phoenix/operator.hpp>
  11. #include <boost/phoenix/statement.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. int main()
  14. {
  15. using boost::phoenix::throw_;
  16. using boost::phoenix::try_;
  17. using boost::phoenix::ref;
  18. using std::exception;
  19. using std::string;
  20. using std::runtime_error;
  21. {
  22. try
  23. {
  24. throw_(runtime_error("error"))();
  25. BOOST_ERROR("exception should have been thrown");
  26. }
  27. catch(runtime_error& err)
  28. {
  29. BOOST_TEST(err.what() == string("error"));
  30. }
  31. }
  32. {
  33. try
  34. {
  35. try
  36. {
  37. throw runtime_error("error");
  38. }
  39. catch(exception&)
  40. {
  41. throw_()();
  42. BOOST_ERROR("exception should have been rethrown");
  43. }
  44. }
  45. catch(exception& err)
  46. {
  47. BOOST_TEST(err.what() == string("error"));
  48. }
  49. }
  50. {
  51. bool caught_exception = false;
  52. try_
  53. [ throw_(runtime_error("error")) ]
  54. .catch_<exception>()
  55. [ ref(caught_exception) = true ]();
  56. BOOST_TEST(caught_exception);
  57. }
  58. {
  59. bool caught_exception = false;
  60. try_
  61. [ throw_(runtime_error("error")) ]
  62. .catch_all
  63. [ ref(caught_exception) = true ]();
  64. BOOST_TEST(caught_exception);
  65. }
  66. {
  67. bool caught_correct_exception = false;
  68. try_
  69. [ throw_(runtime_error("error")) ]
  70. .catch_<string>()
  71. [ ref(caught_correct_exception) = false ]
  72. .catch_<exception>()
  73. [ ref(caught_correct_exception) = true]();
  74. BOOST_TEST(caught_correct_exception);
  75. }
  76. {
  77. bool caught_correct_exception = false;
  78. try_
  79. [ throw_(runtime_error("error")) ]
  80. .catch_<string>()
  81. [ ref(caught_correct_exception) = false ]
  82. .catch_all
  83. [ ref(caught_correct_exception) = true]();
  84. BOOST_TEST(caught_correct_exception);
  85. }
  86. return boost::report_errors();
  87. }