improved error handling

actorid
Marc Zinnschlag 12 years ago
parent afc2e840ae
commit e9ba7339f3

@ -95,6 +95,11 @@ namespace Files
return iter->second; return iter->second;
} }
bool MultiDirCollection::doesExist (const std::string& file) const
{
return mFiles.find (file)!=mFiles.end();
}
MultiDirCollection::TIter MultiDirCollection::begin() const MultiDirCollection::TIter MultiDirCollection::begin() const
{ {
return mFiles.begin(); return mFiles.begin();

@ -73,6 +73,9 @@ namespace Files
/// If the file does not exist, an exception is thrown. \a file must include /// If the file does not exist, an exception is thrown. \a file must include
/// the extension. /// the extension.
bool doesExist (const std::string& file) const;
///< \return Does a file with the given name exist?
TIter begin() const; TIter begin() const;
///< Return iterator pointing to the first file. ///< Return iterator pointing to the first file.

@ -24,22 +24,18 @@ namespace Translation
const std::string& extension, const std::string& extension,
const Files::Collections& dataFileCollections) const Files::Collections& dataFileCollections)
{ {
std::string path; std::string fileName = fileNameNoExtension + extension;
try
{
path = dataFileCollections.getCollection(extension).getPath(fileNameNoExtension + extension).string();
}
catch(...)
{
//no file
return;
}
std::ifstream stream(path); if (dataFileCollections.getCollection (extension).doesExist (fileName))
if (stream.is_open())
{ {
std::string path = dataFileCollections.getCollection (extension).getPath (fileName).string();
std::ifstream stream (path);
if (!stream.is_open())
throw std::runtime_error ("failed to open translation file: " + fileName);
loadDataFromStream(container, stream); loadDataFromStream(container, stream);
stream.close();
} }
} }

Loading…
Cancel
Save