From 42752616c307bfb5a25fda5dae38c5e3d2f21694 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 22 Aug 2019 01:06:52 +0300 Subject: [PATCH] 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. --- source/loader.h | 4 ++++ 1 file changed, 4 insertions(+) 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...); -- 2.43.0