no_exceptions_test.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #define BOOST_NO_EXCEPTIONS
  5. #include <boost/config.hpp>
  6. #include <boost/throw_exception.hpp>
  7. #include <boost/exception/info.hpp>
  8. #include <boost/exception/diagnostic_information.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <stdlib.h>
  11. struct
  12. my_exception:
  13. boost::exception,
  14. std::exception
  15. {
  16. char const *
  17. what() const BOOST_NOEXCEPT_OR_NOTHROW
  18. {
  19. return "my_exception";
  20. }
  21. };
  22. typedef boost::error_info<struct my_tag,int> my_int;
  23. bool called=false;
  24. namespace
  25. boost
  26. {
  27. void
  28. throw_exception( std::exception const & x )
  29. {
  30. called=true;
  31. std::string s=boost::diagnostic_information(x);
  32. std::cout << s;
  33. #ifndef BOOST_NO_RTTI
  34. BOOST_TEST(s.find("my_tag")!=std::string::npos);
  35. #endif
  36. exit(boost::report_errors());
  37. }
  38. }
  39. int
  40. main()
  41. {
  42. BOOST_THROW_EXCEPTION( my_exception() << my_int(42) );
  43. BOOST_TEST(called);
  44. return boost::report_errors();
  45. }