exception.hpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // boost/filesystem/exception.hpp -----------------------------------------------------//
  2. // Copyright Beman Dawes 2003
  3. // Copyright Andrey Semashev 2019
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. // Library home page: http://www.boost.org/libs/filesystem
  7. #ifndef BOOST_FILESYSTEM_EXCEPTION_HPP
  8. #define BOOST_FILESYSTEM_EXCEPTION_HPP
  9. #include <boost/filesystem/config.hpp>
  10. #include <boost/filesystem/path.hpp>
  11. #include <string>
  12. #include <boost/system/error_code.hpp>
  13. #include <boost/system/system_error.hpp>
  14. #include <boost/smart_ptr/intrusive_ptr.hpp>
  15. #include <boost/smart_ptr/intrusive_ref_counter.hpp>
  16. #include <boost/filesystem/detail/header.hpp> // must be the last #include
  17. namespace boost {
  18. namespace filesystem {
  19. //--------------------------------------------------------------------------------------//
  20. // //
  21. // class filesystem_error //
  22. // //
  23. //--------------------------------------------------------------------------------------//
  24. class BOOST_SYMBOL_VISIBLE filesystem_error :
  25. public system::system_error
  26. {
  27. // see http://www.boost.org/more/error_handling.html for design rationale
  28. public:
  29. BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, system::error_code ec);
  30. BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, system::error_code ec);
  31. BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec);
  32. BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec);
  33. BOOST_FILESYSTEM_DECL filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec);
  34. BOOST_FILESYSTEM_DECL filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec);
  35. BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that);
  36. BOOST_FILESYSTEM_DECL filesystem_error& operator=(filesystem_error const& that);
  37. BOOST_FILESYSTEM_DECL ~filesystem_error() noexcept;
  38. path const& path1() const noexcept
  39. {
  40. return m_imp_ptr.get() ? m_imp_ptr->m_path1 : get_empty_path();
  41. }
  42. path const& path2() const noexcept
  43. {
  44. return m_imp_ptr.get() ? m_imp_ptr->m_path2 : get_empty_path();
  45. }
  46. BOOST_FILESYSTEM_DECL const char* what() const noexcept override;
  47. private:
  48. BOOST_FILESYSTEM_DECL static path const& get_empty_path() noexcept;
  49. private:
  50. struct impl :
  51. public boost::intrusive_ref_counter< impl >
  52. {
  53. path m_path1; // may be empty()
  54. path m_path2; // may be empty()
  55. std::string m_what; // not built until needed
  56. impl() = default;
  57. explicit impl(path const& path1) :
  58. m_path1(path1)
  59. {
  60. }
  61. impl(path const& path1, path const& path2) :
  62. m_path1(path1), m_path2(path2)
  63. {
  64. }
  65. };
  66. boost::intrusive_ptr< impl > m_imp_ptr;
  67. };
  68. } // namespace filesystem
  69. } // namespace boost
  70. #include <boost/filesystem/detail/footer.hpp>
  71. #endif // BOOST_FILESYSTEM_EXCEPTION_HPP