1 // Copyright (c) 2014-2018 Dr. Colin Hirsch and Daniel Frey 2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ 3 4 #ifndef TAO_PEGTL_INPUT_ERROR_HPP 5 #define TAO_PEGTL_INPUT_ERROR_HPP 6 7 #include <cerrno> 8 #include <sstream> 9 #include <stdexcept> 10 11 #include "config.hpp" 12 13 namespace tao 14 { 15 namespace TAO_PEGTL_NAMESPACE 16 { 17 struct input_error 18 : std::runtime_error 19 { input_errortao::TAO_PEGTL_NAMESPACE::input_error20 input_error( const std::string& message, const int in_errorno ) 21 : std::runtime_error( message ), 22 errorno( in_errorno ) 23 { 24 } 25 26 int errorno; 27 }; 28 29 } // namespace TAO_PEGTL_NAMESPACE 30 31 } // namespace tao 32 33 #define TAO_PEGTL_INTERNAL_UNWRAP( ... ) __VA_ARGS__ 34 35 #define TAO_PEGTL_THROW_INPUT_ERROR( MESSAGE ) \ 36 do { \ 37 const int errorno = errno; \ 38 std::ostringstream oss; \ 39 oss << "pegtl: " << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ) << " errno " << errorno; \ 40 throw tao::TAO_PEGTL_NAMESPACE::input_error( oss.str(), errorno ); \ 41 } while( false ) 42 43 #define TAO_PEGTL_THROW_INPUT_WIN32_ERROR( MESSAGE ) \ 44 do { \ 45 const int errorno = GetLastError(); \ 46 std::ostringstream oss; \ 47 oss << "pegtl: " << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ) << " GetLastError() " << errorno; \ 48 throw tao::TAO_PEGTL_NAMESPACE::input_error( oss.str(), errorno ); \ 49 } while( false ) 50 51 #endif 52