Refactor catch(...) handlers in Http, OctoPrint, PrintHost, and Serial
This commit is contained in:
parent
baaf66d138
commit
f937209619
4 changed files with 9 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <exception>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ size_t Http::priv::form_file_read_cb(char *buffer, size_t size, size_t nitems, v
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stream->read(buffer, size * nitems);
|
stream->read(buffer, size * nitems);
|
||||||
} catch (...) {
|
} catch (const std::exception &) {
|
||||||
return CURL_READFUNC_ABORT;
|
return CURL_READFUNC_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <exception>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
@ -69,7 +70,7 @@ bool OctoPrint::test(wxString &msg) const
|
||||||
msg = wxString::Format(_(L("Mismatched type of print host: %s")), text ? *text : "OctoPrint");
|
msg = wxString::Format(_(L("Mismatched type of print host: %s")), text ? *text : "OctoPrint");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (const std::exception &) {
|
||||||
res = false;
|
res = false;
|
||||||
msg = "Could not parse server response";
|
msg = "Could not parse server response";
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,8 +170,6 @@ void PrintHostJobQueue::priv::bg_thread_main()
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
emit_error(e.what());
|
emit_error(e.what());
|
||||||
} catch (...) {
|
|
||||||
emit_error("Unknown exception");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup leftover files, if any
|
// Cleanup leftover files, if any
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <exception>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
@ -71,13 +72,10 @@ void parse_hardware_id(const std::string &hardware_id, SerialPortInfo &spi)
|
||||||
std::regex pattern("USB\\\\.*VID_([[:xdigit:]]+)&PID_([[:xdigit:]]+).*");
|
std::regex pattern("USB\\\\.*VID_([[:xdigit:]]+)&PID_([[:xdigit:]]+).*");
|
||||||
std::smatch matches;
|
std::smatch matches;
|
||||||
if (std::regex_match(hardware_id, matches, pattern)) {
|
if (std::regex_match(hardware_id, matches, pattern)) {
|
||||||
try {
|
vid = std::stoul(matches[1].str(), 0, 16);
|
||||||
vid = std::stoul(matches[1].str(), 0, 16);
|
pid = std::stoul(matches[2].str(), 0, 16);
|
||||||
pid = std::stoul(matches[2].str(), 0, 16);
|
spi.id_vendor = vid;
|
||||||
spi.id_vendor = vid;
|
spi.id_product = pid;
|
||||||
spi.id_product = pid;
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue