From 2e5d463e4557a6ea2c9e240f1ffb4da4fec7a5d6 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 11 Apr 2020 00:22:08 +0200 Subject: [PATCH] Throw clean exception when no volatile script is found when adding one. --- src/Battling/Models/Battle.cpp | 5 +++++ src/Battling/Models/Creature.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index a8f3155..1a6f8c4 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -129,6 +129,11 @@ void Battle::AddVolatileScript(const ConstString& key) { return; } script = _library->LoadScript(ScriptCategory::Battle, key); + if (script == nullptr) { + std::stringstream ss; + ss << "Invalid volatile script requested for battle: '" << key.c_str() << "'."; + throw CreatureException(ss.str()); + } return _volatile.Add(script); } void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); } diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 688e7b5..984fc4c 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -217,6 +217,11 @@ void Battling::Creature::AddVolatileScript(const ConstString& name) { return; } script = this->_library->LoadScript(ScriptCategory::Creature, name); + if (script == nullptr) { + std::stringstream ss; + ss << "Invalid volatile script requested for creature: '" << name.c_str() << "'."; + throw CreatureException(ss.str()); + } _volatile.Add(script); }