Fix: Don't throw const char* but std::runtime_erro

This commit is contained in:
Michael Höß 2020-11-30 21:10:42 +01:00
parent dd51803e15
commit 059dee7d4b
2 changed files with 5 additions and 7 deletions

View File

@ -98,8 +98,7 @@ void HumiReader::setCallback(std::function<bool(const HumiResult&)> cb) {
void HumiReader::run() { void HumiReader::run() {
if (!setupDevice()) { if (!setupDevice()) {
throw std::runtime_error("Can't setup device\n"); throw std::runtime_error("Can't setup device");
//throw "Can't setup device";
} }
cancelLoop = false; cancelLoop = false;
hasIResult = false; hasIResult = false;
@ -108,17 +107,17 @@ void HumiReader::run() {
char buf[32+1]; char buf[32+1];
char outbuf[256]; char outbuf[256];
unsigned int outbufsiz =0; unsigned int outbufsiz =0;
unsigned int sleepMax = 10000; int sleepMax = 10000;
while(!cancelLoop) { while(!cancelLoop) {
int siz = read(fd, buf, sizeof(buf)-1); int siz = read(fd, buf, sizeof(buf)-1);
if (siz < 0) { if (siz < 0) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
throw "Read failed"; throw std::runtime_error("Read failed");
} }
else { else {
if (sleepMax <= 0) { if (sleepMax <= 0) {
throw "Timeout"; throw std::runtime_error("Timeout");
} }
usleep(10*1000); usleep(10*1000);
sleepMax -= 10; sleepMax -= 10;

View File

@ -137,8 +137,7 @@ int main(int argc, char **argv)
return 0; return 0;
} }
catch (const std::exception& e) { catch (const std::exception& e) {
std::cerr << "Error executing " << e.what(); std::cerr << "Error executing " << e.what() << std::endl;
return 1; return 1;
} }
} }