improved error handling

actorid
Marc Zinnschlag 12 years ago
parent afc2e840ae
commit e9ba7339f3

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

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

@ -24,22 +24,18 @@ namespace Translation
const std::string& extension,
const Files::Collections& dataFileCollections)
{
std::string path;
try
{
path = dataFileCollections.getCollection(extension).getPath(fileNameNoExtension + extension).string();
}
catch(...)
{
//no file
return;
}
std::string fileName = fileNameNoExtension + extension;
std::ifstream stream(path);
if (stream.is_open())
if (dataFileCollections.getCollection (extension).doesExist (fileName))
{
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);
stream.close();
}
}

Loading…
Cancel
Save