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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user