RtError.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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,
  19. DEBUG_WARNING,
  20. UNSPECIFIED,
  21. NO_DEVICES_FOUND,
  22. INVALID_DEVICE,
  23. INVALID_STREAM,
  24. MEMORY_ERROR,
  25. INVALID_PARAMETER,
  26. DRIVER_ERROR,
  27. SYSTEM_ERROR,
  28. THREAD_ERROR
  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 stdout.
  39. virtual void printMessage(void) { std::cout << '\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. };
  45. #endif