Skip to content

Commit

Permalink
Merge pull request #53 from mbertrone/pr/get_port_exception
Browse files Browse the repository at this point in the history
improve get_port() error message if no port present
  • Loading branch information
acloudiator authored Jan 31, 2019
2 parents 190adab + 1f9da29 commit 4b505ec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libs/polycube/include/polycube/services/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,19 @@ void Cube<PortType>::impl::remove_port(const std::string &port_name) {

template <class PortType>
std::shared_ptr<PortType> Cube<PortType>::impl::get_port(const std::string &port_name) {
if (ports_by_name_.count(port_name) == 0) {
throw std::runtime_error("Port " + port_name + " does not exist");
}

return ports_by_name_.at(port_name);
}

template <class PortType>
std::shared_ptr<PortType> Cube<PortType>::impl::get_port(int index) {
if (ports_by_id_.count(index) == 0) {
throw std::runtime_error("Port id " + std::to_string(index) + " does not exist");
}

return ports_by_id_.at(index);
}

Expand Down

0 comments on commit 4b505ec

Please sign in to comment.