Skip to content

Commit

Permalink
Throw exceptions in c'tor
Browse files Browse the repository at this point in the history
  • Loading branch information
souryavarenya authored Jan 23, 2024
1 parent aae8ce8 commit 2f27504
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fixposition_driver_lib/src/fixposition_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <stdexcept>

/* PACKAGE */
#include <fixposition_driver_lib/converter/imu.hpp>
Expand Down Expand Up @@ -44,7 +45,16 @@

namespace fixposition {
FixpositionDriver::FixpositionDriver(const FixpositionDriverParams& params) : params_(params) {
Connect();
// connect to the sensor
if (!Connect()) {
if (params_.fp_output.type == INPUT_TYPE::TCP) {
throw std::runtime_error("Unable to connect to the sensor via TCP");
} else if (params_.fp_output.type == INPUT_TYPE::SERIAL) {
throw std::runtime_error("Unable to connect to the sensor via Serial");
} else {
throw std::runtime_error("Unable to connect to the sensor, verify configuration");
}
}

// static headers
rawdmi_.head1 = 0xaa;
Expand All @@ -63,7 +73,7 @@ FixpositionDriver::FixpositionDriver(const FixpositionDriverParams& params) : pa

// initialize converters
if (!InitializeConverters()) {
std::cerr << "Could not initialize output converter!\n";
throw std::runtime_error("Could not initialize output converter!");
}
}

Expand Down

0 comments on commit 2f27504

Please sign in to comment.