Replace uses of throw by carla::throw_exception

This commit is contained in:
nsubiron 2019-01-26 16:10:52 +01:00
parent 459d75568a
commit d0137fecc7
13 changed files with 40 additions and 23 deletions

View File

@ -28,6 +28,7 @@ C++
rare occasions if it results in clearer code.
* Compilation should not give any error or warning
(`clang++-6.0 -Wall -Wextra -std=C++14 -Wno-missing-braces`).
* The use of `throw` is forbidden, use `carla::throw_exception` instead.
* Unreal C++ code (CarlaUE4 and Carla plugin) follow the
[Unreal Engine's Coding Standard][ue4link] with the exception of using
spaces instead of tabs.

View File

@ -6,6 +6,7 @@
#pragma once
#include "carla/Exception.h"
#include "carla/Time.h"
#include <boost/variant.hpp>
@ -99,10 +100,12 @@ namespace detail {
std::unique_lock<std::mutex> lock(_mutex);
auto &r = _map[&detail::thread_tag];
r.should_wait = true;
if (!_cv.wait_for(lock, timeout.to_chrono(), [&]() { return !r.should_wait; }))
throw std::runtime_error("RecurrentSharedFuture.WaitFor: time-out");
if (r.value.which() == 1)
throw boost::get<SharedException>(r.value);
if (!_cv.wait_for(lock, timeout.to_chrono(), [&]() { return !r.should_wait; })) {
throw_exception(std::runtime_error("RecurrentSharedFuture.WaitFor: time-out"));
}
if (r.value.which() == 1) {
throw_exception(boost::get<SharedException>(r.value));
}
return boost::get<T>(std::move(r.value));
}

View File

@ -6,16 +6,17 @@
#include "carla/client/ActorAttribute.h"
#include "carla/Exception.h"
#include "carla/Logging.h"
#include "carla/StringUtil.h"
namespace carla {
namespace client {
#define LIBCARLA_THROW_INVALID_VALUE(message) throw InvalidAttributeValue(GetId() + ": " + message);
#define LIBCARLA_THROW_INVALID_VALUE(message) throw_exception(InvalidAttributeValue(GetId() + ": " + message));
#define LIBCARLA_THROW_BAD_VALUE_CAST(type) \
if (GetType() != rpc::ActorAttributeType:: type) { \
throw BadAttributeCast(GetId() + ": bad attribute cast: cannot convert to " #type); \
throw_exception(BadAttributeCast(GetId() + ": bad attribute cast: cannot convert to " #type)); \
}
void ActorAttribute::Set(std::string value) {

View File

@ -41,7 +41,7 @@ namespace client {
auto it = _attributes.find(id);
if (it == _attributes.end()) {
using namespace std::string_literals;
throw std::out_of_range("attribute '"s + id + "' not found");
throw_exception(std::out_of_range("attribute '"s + id + "' not found"));
}
return it->second;
}

View File

@ -6,6 +6,8 @@
#include "carla/client/BlueprintLibrary.h"
#include "carla/Exception.h"
#include <algorithm>
#include <iterator>
@ -40,14 +42,15 @@ namespace client {
auto it = _blueprints.find(key);
if (it == _blueprints.end()) {
using namespace std::string_literals;
throw std::out_of_range("blueprint '"s + key + "' not found");
throw_exception(std::out_of_range("blueprint '"s + key + "' not found"));
}
return it->second;
}
BlueprintLibrary::const_reference BlueprintLibrary::at(size_type pos) const {
if (pos >= size())
throw std::out_of_range("index out of range");
if (pos >= size()) {
throw_exception(std::out_of_range("index out of range"));
}
return operator[](pos);
}

View File

@ -71,7 +71,7 @@ namespace client {
}
if (GetParent() == nullptr) {
throw std::runtime_error(GetDisplayId() + ": not attached to vehicle");
throw_exception(std::runtime_error(GetDisplayId() + ": not attached to vehicle"));
return;
}

View File

@ -75,7 +75,7 @@ namespace client {
}
void LaneDetector::Stop() {
throw std::runtime_error("LaneDetector::Stop(): not implemented.");
throw_exception(std::runtime_error("LaneDetector::Stop(): not implemented."));
}
SharedPtr<sensor::SensorData> LaneDetector::TickLaneDetector(

View File

@ -6,6 +6,7 @@
#include "carla/client/detail/EpisodeProxy.h"
#include "carla/Exception.h"
#include "carla/client/detail/Simulator.h"
#include <exception>
@ -38,14 +39,14 @@ namespace detail {
typename EpisodeProxyImpl<T>::SharedPtrType EpisodeProxyImpl<T>::Lock() const {
auto ptr = Load(_simulator);
if (ptr == nullptr) {
throw std::runtime_error(
throw_exception(std::runtime_error(
"trying to operate on a destroyed actor; an actor's function "
"was called, but the actor is already destroyed.");
"was called, but the actor is already destroyed."));
}
if (_episode_id != ptr->GetCurrentEpisodeId()) {
throw std::runtime_error(
throw_exception(std::runtime_error(
"trying to access an expired episode; a new episode was started "
"in the simulation but an object tried accessing the old one.");
"in the simulation but an object tried accessing the old one."));
}
return ptr;
}

View File

@ -6,13 +6,16 @@
#include "carla/rpc/Server.h"
#include <rpc/this_handler.h>
#include "carla/Exception.h"
#include <exception>
namespace carla {
namespace rpc {
void Server::RespondError(std::string error_message) {
::rpc::this_handler().respond_error(std::move(error_message));
/// @todo Remove this function.
::carla::throw_exception(std::runtime_error(std::move(error_message)));
}
} // namespace carla

View File

@ -7,6 +7,7 @@
#pragma once
#include "carla/Debug.h"
#include "carla/Exception.h"
#include "carla/sensor/SensorData.h"
#include <exception>
@ -107,14 +108,14 @@ namespace data {
reference at(size_type pos) {
if (!(pos < size())) {
throw std::out_of_range("Array index out of range");
throw_exception(std::out_of_range("Array index out of range"));
}
return operator[](pos);
}
const_reference at(size_type pos) const {
if (!(pos < size())) {
throw std::out_of_range("Array index out of range");
throw_exception(std::out_of_range("Array index out of range"));
}
return operator[](pos);
}

View File

@ -6,6 +6,7 @@
#include "carla/streaming/detail/Dispatcher.h"
#include "carla/Exception.h"
#include "carla/Logging.h"
#include "carla/streaming/detail/MultiStreamState.h"
#include "carla/streaming/detail/StreamState.h"
@ -21,7 +22,7 @@ namespace detail {
auto ptr = std::make_shared<StreamStateT>(cached_token);
auto result = stream_map.emplace(std::make_pair(cached_token.get_stream_id(), ptr));
if (!result.second) {
throw std::runtime_error("failed to create stream!");
throw_exception(std::runtime_error("failed to create stream!"));
}
return ptr;
}

View File

@ -6,6 +6,8 @@
#include "carla/streaming/detail/Token.h"
#include "carla/Exception.h"
#include <cstring>
#include <exception>
@ -21,7 +23,7 @@ namespace detail {
_token.address_type = token_data::address::ip_v6;
_token.address.v6 = addr.to_v6().to_bytes();
} else {
throw std::invalid_argument("invalid ip address!");
throw_exception(std::invalid_argument("invalid ip address!"));
}
}

View File

@ -8,6 +8,7 @@
#include "carla/BufferPool.h"
#include "carla/Debug.h"
#include "carla/Exception.h"
#include "carla/Logging.h"
#include "carla/Time.h"
@ -75,7 +76,7 @@ namespace tcp {
_connection_timer(io_service),
_buffer_pool(std::make_shared<BufferPool>()) {
if (!_token.protocol_is_tcp()) {
throw std::invalid_argument("invalid token, only TCP tokens supported");
throw_exception(std::invalid_argument("invalid token, only TCP tokens supported"));
}
}