system_error.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef BOOST_SYSTEM_SYSTEM_ERROR_HPP
  2. #define BOOST_SYSTEM_SYSTEM_ERROR_HPP
  3. // Copyright Beman Dawes 2006
  4. // Copyright Peter Dimov 2021
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // https://www.boost.org/LICENSE_1_0.txt
  7. #include <boost/system/errc.hpp>
  8. #include <boost/system/detail/error_code.hpp>
  9. #include <string>
  10. #include <stdexcept>
  11. #include <cassert>
  12. namespace boost
  13. {
  14. namespace system
  15. {
  16. class BOOST_SYMBOL_VISIBLE system_error: public std::runtime_error
  17. {
  18. private:
  19. error_code code_;
  20. public:
  21. explicit system_error( error_code const & ec ):
  22. std::runtime_error( ec.what() ), code_( ec ) {}
  23. system_error( error_code const & ec, std::string const & prefix ):
  24. std::runtime_error( prefix + ": " + ec.what() ), code_( ec ) {}
  25. system_error( error_code const & ec, char const * prefix ):
  26. std::runtime_error( std::string( prefix ) + ": " + ec.what() ), code_( ec ) {}
  27. system_error( int ev, error_category const & ecat ):
  28. std::runtime_error( error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
  29. system_error( int ev, error_category const & ecat, std::string const & prefix ):
  30. std::runtime_error( prefix + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
  31. system_error( int ev, error_category const & ecat, char const * prefix ):
  32. std::runtime_error( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
  33. error_code code() const noexcept
  34. {
  35. return code_;
  36. }
  37. };
  38. } // namespace system
  39. } // namespace boost
  40. #endif // BOOST_SYSTEM_SYSTEM_ERROR_HPP