Skip to content

Commit

Permalink
custom exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 16, 2024
1 parent a03866d commit d976130
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/solver/systemParser/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,30 @@ using namespace Antares::Study;
namespace Antares::Solver::SystemConverter
{

class ErrorWhileSplittingLibraryAndModel: public std::runtime_error
{
public:
explicit ErrorWhileSplittingLibraryAndModel(const std::string& s):
runtime_error("'.' not found while splitting library and model: " + s)
{
}
};

class LibraryNotFound: public std::runtime_error
{
public:
explicit LibraryNotFound(const std::string& s):
runtime_error("No library found with this name: " + s)
{
}
};

static std::pair<std::string, std::string> splitLibraryModelString(const std::string& s)
{
size_t pos = s.find('.');
if (pos == std::string::npos)
{
throw std::runtime_error("Error while splitting library model: " + s
+ "Correct format is lirabry.model");
throw ErrorWhileSplittingLibraryAndModel(s);
}

std::string library = s.substr(0, pos);
Expand All @@ -53,7 +70,7 @@ static const SystemModel::Model* getModel(const std::vector<SystemModel::Library
[&libraryId](const auto& l) { return l.Id() == libraryId; });
if (lib == libraries.end())
{
throw std::runtime_error("No libraries named: " + libraryId);
throw LibraryNotFound(libraryId);
}

auto& model = lib->Models().at(modelId);
Expand Down

0 comments on commit d976130

Please sign in to comment.