diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 3a60cb6b5..1a0c8f5e9 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -22,7 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM::OSRM(const char * server_ini_path) { if( !testDataFile(server_ini_path) ){ - throw OSRMException("server.ini not found"); + std::string error_message = std::string(server_ini_path) + " not found"; + throw OSRMException(error_message.c_str()); } IniFile serverConfig(server_ini_path); diff --git a/Util/IniFile.h b/Util/IniFile.h index aa5c4b9c2..582cc273c 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -25,29 +25,36 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/HashTable.h" #include +#include +#include #include -#include #include #include class IniFile { public: - IniFile(const char * configFile) { - std::ifstream config( configFile ); - if(!config) { - std::string str = "[config] " + std::string(configFile) + " not found"; - throw OSRMException(str.c_str()); + IniFile(const char * config_filename) { + boost::filesystem::path config_file(config_filename); + if ( !boost::filesystem::exists( config_file ) ) { + std::string error = std::string(config_filename) + " not found"; + throw OSRMException(error); + } + if ( 0 == boost::filesystem::file_size( config_file ) ) { + std::string error = std::string(config_filename) + " is empty"; + throw OSRMException(error); } + boost::filesystem::ifstream config( config_file ); std::string line; if (config.is_open()) { while ( config.good() ) { getline (config,line); std::vector tokens; Tokenize(line, tokens); - if(2 == tokens.size() ) + if(2 == tokens.size() ) { parameters.insert(std::make_pair(tokens[0], tokens[1])); + } } config.close(); } diff --git a/Util/OSRMException.h b/Util/OSRMException.h index dcae24e18..804255a3c 100644 --- a/Util/OSRMException.h +++ b/Util/OSRMException.h @@ -22,15 +22,18 @@ or see http://www.gnu.org/licenses/agpl.txt. #define OSRM_EXCEPTION_H #include +#include class OSRMException: public std::exception { public: OSRMException(const char * message) : message(message) {} + OSRMException(const std::string & message) : message(message) {} + virtual ~OSRMException() throw() {} private: virtual const char* what() const throw() { - return message; + return message.c_str(); } - const char * message; + const std::string message; }; -#endif /* OSRM_EXCEPTION_H */ \ No newline at end of file +#endif /* OSRM_EXCEPTION_H */