From da5629982b65a4cbf31abc30a0cf930801fcc940 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 5 Sep 2015 23:05:22 +0300 Subject: [PATCH] Throw a resource_load_error if the source could not be opened --- source/resourcemanager.cpp | 7 +++++++ source/resourcemanager.h | 1 + 2 files changed, 8 insertions(+) diff --git a/source/resourcemanager.cpp b/source/resourcemanager.cpp index e989a5d0..733cfaff 100644 --- a/source/resourcemanager.cpp +++ b/source/resourcemanager.cpp @@ -11,6 +11,10 @@ using namespace std; namespace Msp { namespace GL { +resource_load_error::resource_load_error(const string &name, const string &err): + runtime_error(format("%s: %s", name, err)) +{ } + resource_load_error::resource_load_error(const string &name, const exception &exc): runtime_error(format("%s: %s: %s", name, Debug::demangle(typeid(exc).name()), exc.what())) { } @@ -276,6 +280,9 @@ ResourceManager::ManagedResource::ManagedResource(Resource &r): void ResourceManager::ManagedResource::start_loading() { io = location.collection->open_raw(location.name); + if(!io) + throw resource_load_error(location.name, "open failed"); + loader = resource->load(*io); if(!loader) { diff --git a/source/resourcemanager.h b/source/resourcemanager.h index 5cc427f7..e7c8c04b 100644 --- a/source/resourcemanager.h +++ b/source/resourcemanager.h @@ -16,6 +16,7 @@ class ResourceWatcher; class resource_load_error: public std::runtime_error { public: + resource_load_error(const std::string &, const std::string &); resource_load_error(const std::string &, const std::exception &); virtual ~resource_load_error() throw() { } }; -- 2.45.2