Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.1KB

  1. /************************************************************************/
  2. /*! \class RtError
  3. \brief Exception handling class for RtAudio & RtMidi.
  4. The RtError class is quite simple but it does allow errors to be
  5. "caught" by RtError::Type. See the RtAudio and RtMidi
  6. documentation to know which methods can throw an RtError.
  7. */
  8. /************************************************************************/
  9. #ifndef RTERROR_H
  10. #define RTERROR_H
  11. #include <exception>
  12. #include <iostream>
  13. #include <string>
  14. class RtError : public std::exception
  15. {
  16. public:
  17. //! Defined RtError types.
  18. enum Type {
  19. WARNING, /*!< A non-critical error. */
  20. DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
  21. UNSPECIFIED, /*!< The default, unspecified error type. */
  22. NO_DEVICES_FOUND, /*!< No devices found on system. */
  23. INVALID_DEVICE, /*!< An invalid device ID was specified. */
  24. MEMORY_ERROR, /*!< An error occured during memory allocation. */
  25. INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
  26. INVALID_USE, /*!< The function was called incorrectly. */
  27. DRIVER_ERROR, /*!< A system driver error occured. */
  28. SYSTEM_ERROR, /*!< A system error occured. */
  29. THREAD_ERROR /*!< A thread error occured. */
  30. };
  31. //! The constructor.
  32. RtError( const std::string& message, Type type = RtError::UNSPECIFIED ) throw() : message_(message), type_(type) {}
  33. //! The destructor.
  34. virtual ~RtError( void ) throw() {}
  35. //! Prints thrown error message to stderr.
  36. virtual void printMessage( void ) const throw() { std::cerr << '\n' << message_ << "\n\n"; }
  37. //! Returns the thrown error message type.
  38. virtual const Type& getType(void) const throw() { return type_; }
  39. //! Returns the thrown error message string.
  40. virtual const std::string& getMessage(void) const throw() { return message_; }
  41. //! Returns the thrown error message as a c-style string.
  42. virtual const char* what( void ) const throw() { return message_.c_str(); }
  43. protected:
  44. std::string message_;
  45. Type type_;
  46. };
  47. #endif