Chris@559: /************************************************************************/ Chris@559: /*! \class RtError Chris@559: \brief Exception handling class for RtAudio & RtMidi. Chris@559: Chris@559: The RtError class is quite simple but it does allow errors to be Chris@559: "caught" by RtError::Type. See the RtAudio and RtMidi Chris@559: documentation to know which methods can throw an RtError. Chris@559: Chris@559: */ Chris@559: /************************************************************************/ Chris@559: Chris@559: #ifndef RTERROR_H Chris@559: #define RTERROR_H Chris@559: Chris@559: #include Chris@559: #include Chris@559: Chris@559: class RtError Chris@559: { Chris@559: public: Chris@559: //! Defined RtError types. Chris@559: enum Type { Chris@559: WARNING, /*!< A non-critical error. */ Chris@559: DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */ Chris@559: UNSPECIFIED, /*!< The default, unspecified error type. */ Chris@559: NO_DEVICES_FOUND, /*!< No devices found on system. */ Chris@559: INVALID_DEVICE, /*!< An invalid device ID was specified. */ Chris@559: INVALID_STREAM, /*!< An invalid stream ID was specified. */ Chris@559: MEMORY_ERROR, /*!< An error occured during memory allocation. */ Chris@559: INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */ Chris@559: DRIVER_ERROR, /*!< A system driver error occured. */ Chris@559: SYSTEM_ERROR, /*!< A system error occured. */ Chris@559: THREAD_ERROR /*!< A thread error occured. */ Chris@559: }; Chris@559: Chris@559: protected: Chris@559: std::string message_; Chris@559: Type type_; Chris@559: Chris@559: public: Chris@559: //! The constructor. Chris@559: RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type) {} Chris@559: Chris@559: //! The destructor. Chris@559: virtual ~RtError(void) {}; Chris@559: Chris@559: //! Prints thrown error message to stderr. Chris@559: virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; } Chris@559: Chris@559: //! Returns the thrown error message type. Chris@559: virtual const Type& getType(void) { return type_; } Chris@559: Chris@559: //! Returns the thrown error message string. Chris@559: virtual const std::string& getMessage(void) { return message_; } Chris@559: Chris@559: //! Returns the thrown error message as a C string. Chris@559: virtual const char *getMessageString(void) { return message_.c_str(); } Chris@559: }; Chris@559: Chris@559: #endif