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