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.

59 lines
1.9KB

  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. UNSPECIFIED, /*!< The default, unspecified error type. */
  20. NO_DEVICES_FOUND, /*!< No devices found on system. */
  21. INVALID_DEVICE, /*!< An invalid device ID was specified. */
  22. MEMORY_ERROR, /*!< An error occured during memory allocation. */
  23. INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
  24. INVALID_USE, /*!< The function was called incorrectly. */
  25. DRIVER_ERROR, /*!< A system driver error occured. */
  26. SYSTEM_ERROR, /*!< A system error occured. */
  27. THREAD_ERROR /*!< A thread error occured. */
  28. };
  29. //! The constructor.
  30. RtError( const std::string& message, Type type = RtError::UNSPECIFIED ) throw() : message_(message), type_(type) {}
  31. //! The destructor.
  32. virtual ~RtError( void ) throw() {}
  33. //! Prints thrown error message to stderr.
  34. virtual void printMessage( void ) throw() { std::cerr << '\n' << message_ << "\n\n"; }
  35. //! Returns the thrown error message type.
  36. virtual const Type& getType(void) throw() { return type_; }
  37. //! Returns the thrown error message string.
  38. virtual const std::string& getMessage(void) throw() { return message_; }
  39. //! Returns the thrown error message as a c-style string.
  40. virtual const char* what( void ) const throw() { return message_.c_str(); }
  41. protected:
  42. std::string message_;
  43. Type type_;
  44. };
  45. #endif