From 059dee7d4bce3a6dd55f0de9a9993f1c74c296ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=B6=C3=9F?= Date: Mon, 30 Nov 2020 21:10:42 +0100 Subject: [PATCH] Fix: Don't throw const char* but std::runtime_erro --- humireader.cpp | 9 ++++----- main.cpp | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/humireader.cpp b/humireader.cpp index a8db6a8..1b00dd2 100644 --- a/humireader.cpp +++ b/humireader.cpp @@ -98,8 +98,7 @@ void HumiReader::setCallback(std::function cb) { void HumiReader::run() { if (!setupDevice()) { - throw std::runtime_error("Can't setup device\n"); - //throw "Can't setup device"; + throw std::runtime_error("Can't setup device"); } cancelLoop = false; hasIResult = false; @@ -108,17 +107,17 @@ void HumiReader::run() { char buf[32+1]; char outbuf[256]; unsigned int outbufsiz =0; - unsigned int sleepMax = 10000; + int sleepMax = 10000; while(!cancelLoop) { int siz = read(fd, buf, sizeof(buf)-1); if (siz < 0) { if (errno != EAGAIN) { - throw "Read failed"; + throw std::runtime_error("Read failed"); } else { if (sleepMax <= 0) { - throw "Timeout"; + throw std::runtime_error("Timeout"); } usleep(10*1000); sleepMax -= 10; diff --git a/main.cpp b/main.cpp index bb38af9..3417a8b 100644 --- a/main.cpp +++ b/main.cpp @@ -137,8 +137,7 @@ int main(int argc, char **argv) return 0; } catch (const std::exception& e) { - std::cerr << "Error executing " << e.what(); + std::cerr << "Error executing " << e.what() << std::endl; return 1; } } -