1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Show proper error message if player attempts to load save with missing

identifiers instead of silent crash to main menu
This commit is contained in:
Ivan Savenko
2023-11-19 19:30:55 +02:00
parent 54480c6209
commit cc71651ee4
5 changed files with 60 additions and 57 deletions

View File

@@ -9,6 +9,19 @@
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
class IdentifierResolutionException : public std::runtime_error
{
public:
const std::string identifierName;
IdentifierResolutionException(const std::string & identifierName )
: std::runtime_error("Failed to resolve identifier " + identifierName)
, identifierName(identifierName)
{}
};
class IdentifierBase
{
protected:
@@ -21,6 +34,11 @@ protected:
{}
~IdentifierBase() = default;
/// Attempts to resolve identifier using provided entity type
/// Returns resolved numeric identifier
/// Throws IdentifierResolutionException on failure
static int32_t resolveIdentifier(const std::string & entityType, const std::string identifier);
public:
int32_t num;
@@ -233,4 +251,4 @@ public:
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VCMI_LIB_NAMESPACE_END