From: Mikko Rasa Date: Wed, 21 Aug 2019 22:06:52 +0000 (+0300) Subject: Throw an exception if trying to load a nonexistent file X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=42752616c307bfb5a25fda5dae38c5e3d2f21694;p=libs%2Fdatafile.git Throw an exception if trying to load a nonexistent file Collection::open_raw returns a null pointer in this case so it must be checked. --- diff --git a/source/loader.h b/source/loader.h index 207ecff..3e39872 100644 --- a/source/loader.h +++ b/source/loader.h @@ -174,6 +174,8 @@ template void load(T &obj, typename T::Loader::Collection &coll, const std::string &fn, Args &... args) { RefPtr 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 EnableIf::value, void>::No load(T &obj, C &coll, const std::string &fn, Args &... args) { RefPtr in = coll.open_raw(fn); + if(!in) + throw IO::file_not_found(fn); Parser parser(*in, fn); typename T::Loader loader(obj, args...);