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.0KB

  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 <iostream>
  12. #include <string>
  13. class RtError
  14. {
  15. public:
  16. //! Defined RtError types.
  17. enum Type {
  18. WARNING, /*!< A non-critical error. */
  19. DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
  20. UNSPECIFIED, /*!< The default, unspecified error type. */
  21. NO_DEVICES_FOUND, /*!< No devices found on system. */
  22. INVALID_DEVICE, /*!< An invalid device ID was specified. */
  23. INVALID_STREAM, /*!< An invalid stream ID was specified. */
  24. MEMORY_ERROR, /*!< An error occured during memory allocation. */
  25. INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
  26. DRIVER_ERROR, /*!< A system driver error occured. */
  27. SYSTEM_ERROR, /*!< A system error occured. */
  28. THREAD_ERROR /*!< A thread error occured. */
  29. };
  30. protected:
  31. std::string message_;
  32. Type type_;
  33. public:
  34. //! The constructor.
  35. RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type) {}
  36. //! The destructor.
  37. virtual ~RtError(void) {};
  38. //! Prints thrown error message to stderr.
  39. virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; }
  40. //! Returns the thrown error message type.
  41. virtual const Type& getType(void) { return type_; }
  42. //! Returns the thrown error message string.
  43. virtual const std::string& getMessage(void) { return message_; }
  44. //! Returns the thrown error message as a C string.
  45. virtual const char *getMessageString(void) { return message_.c_str(); }
  46. };
  47. #endif