From 594f06511673e323650866654695d266d024ac07 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Mon, 12 Jul 2021 08:05:25 +0200 Subject: [PATCH] ftdipp_mpsse: use runtime_error instead of simple exception --- src/ftdipp_mpsse.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ftdipp_mpsse.cpp b/src/ftdipp_mpsse.cpp index 5d5a44b..3990a64 100644 --- a/src/ftdipp_mpsse.cpp +++ b/src/ftdipp_mpsse.cpp @@ -10,6 +10,7 @@ #include #include +#include #ifdef USE_UDEV #include @@ -36,7 +37,7 @@ FTDIpp_MPSSE::FTDIpp_MPSSE(const mpsse_bit_config &cable, const string &dev, if (!dev.empty()) { if (!search_with_dev(dev)) { cerr << "No cable found" << endl; - throw std::exception(); + throw std::runtime_error("No cable found"); } } else { _vid = cable.vid; @@ -49,7 +50,7 @@ FTDIpp_MPSSE::FTDIpp_MPSSE(const mpsse_bit_config &cable, const string &dev, _buffer = (unsigned char *)malloc(sizeof(unsigned char) * _buffer_size); if (!_buffer) { cout << "_buffer malloc failed" << endl; - throw std::exception(); + throw std::runtime_error("_buffer malloc failed"); } } @@ -71,7 +72,7 @@ void FTDIpp_MPSSE::open_device(const std::string &serial, unsigned int baudrate) _ftdi = ftdi_new(); if (_ftdi == NULL) { cout << "open_device: failed to initialize ftdi" << endl; - throw std::exception(); + throw std::runtime_error("open_device: failed to initialize ftdi"); } #if (ATTACH_KERNEL && (FTDI_VERSION >= 105)) _ftdi->module_detach_mode = AUTO_DETACH_REATACH_SIO_MODULE; @@ -90,12 +91,12 @@ void FTDIpp_MPSSE::open_device(const std::string &serial, unsigned int baudrate) fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(_ftdi)); ftdi_free(_ftdi); - throw std::exception(); + throw std::runtime_error("unable to open ftdi device"); } if (ftdi_set_baudrate(_ftdi, baudrate) < 0) { fprintf(stderr, "baudrate error\n"); close_device(); - throw std::exception(); + throw std::runtime_error("baudrate error"); } } @@ -108,7 +109,6 @@ void FTDIpp_MPSSE::ftdi_usb_close_internal() int FTDIpp_MPSSE::close_device() { - int rtn; if (_ftdi == NULL) return EXIT_FAILURE; @@ -121,7 +121,7 @@ int FTDIpp_MPSSE::close_device() * repompe de la fonction et des suivantes */ if (_ftdi->usb_dev != NULL) { - rtn = libusb_release_interface(_ftdi->usb_dev, _ftdi->interface); + int rtn = libusb_release_interface(_ftdi->usb_dev, _ftdi->interface); if (rtn < 0) { fprintf(stderr, "release interface failed %d\n", rtn); return EXIT_FAILURE;