USBException

Name

USBException -- Report errors from libUSB1

Synopsis


g++ yourstuff -L$DAQLIB -Wl-rpath=$DAQLIB -llibUSB1 \
   `pkg-config libusb-1.0 --libs` `pkg-config libusb-1.0 --cflags`         
      

#include <USB.h>
class USBException : public std::exception
{
public:
    USBException(int code, const std::string& msg)  noexcept;
    USBException(const USBException& rhs) noexcept;
    USBException& operator=(const USBException& rhs) noexcept;
    
    virtual const char* what() const noexcept;
    
};         
      

DESCRIPTION

This class is intended to be used to signal errors by the USB library. The code parmaeter for the constructor is a lower lever library error code and is used to create the final error message produced by the what method.

EXAMPLES

Catching the detailed exception:


#include <USB.h>
#include <iostream>
#include <stdlib.h>
...
{
...
   try {
       // Some libUSB1 calls in this block:
   }
   catch (USBException& e) {
       std::cerr << "An error occured during a USB call: \n";
       std::cerr << e.what() << std::endl;
       exit(EXIT_FAILURE);
   }
   ...
}
         

If all you want to do is kill the program on any exception you don't need to catch the detailed exception take advantage of the fact that USBException is derived from std::exception and be sure to catch std::exception by reference so the proper what method is executed e.g.:


#include <stdexcept>
#include <iostream>
#include <stdlib.h>
...
{
...
   try {
       // Some libUSB1 calls in this block:
   }
   catch (std::exception& e) {
       std::cerr << "An error occured: \n";
       std::cerr << e.what() << std::endl;
       exit(EXIT_FAILURE);
   }
   ...
}