]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/loader.h
Throw an exception if trying to load a nonexistent file
[libs/datafile.git] / source / loader.h
index 207ecff8dff8d7f068aa033994ef2a5e608ba56a..3e39872a5c2f1263d6748a761d28a52baa97e0f7 100644 (file)
@@ -174,6 +174,8 @@ template<typename T, typename... Args>
 void load(T &obj, typename T::Loader::Collection &coll, const std::string &fn, Args &... args)
 {
        RefPtr<IO::Seekable> in = coll.open_raw(fn);
+       if(!in)
+               throw IO::file_not_found(fn);
 
        Parser parser(*in, fn);
        typename T::Loader loader(obj, coll, args...);
@@ -188,6 +190,8 @@ template<typename T, typename C, typename... Args>
 typename EnableIf<NeedsCollection<typename T::Loader>::value, void>::No load(T &obj, C &coll, const std::string &fn, Args &... args)
 {
        RefPtr<IO::Seekable> in = coll.open_raw(fn);
+       if(!in)
+               throw IO::file_not_found(fn);
 
        Parser parser(*in, fn);
        typename T::Loader loader(obj, args...);