Bug fix in probing documentation
[rtaudio-cdist.git] / RtError.h
1 /************************************************************************/
2 /*! \class RtError
3     \brief Exception handling class for RtAudio & RtMidi.
4
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.
8
9 */
10 /************************************************************************/
11
12 #ifndef RTERROR_H
13 #define RTERROR_H
14
15 #include <exception>
16 #include <iostream>
17 #include <string>
18
19 class RtError : public std::exception
20 {
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. */
35   };
36
37   //! The constructor.
38   RtError( const std::string& message, Type type = RtError::UNSPECIFIED ) throw() : message_(message), type_(type) {}
39  
40   //! The destructor.
41   virtual ~RtError( void ) throw() {}
42
43   //! Prints thrown error message to stderr.
44   virtual void printMessage( void ) const throw() { std::cerr << '\n' << message_ << "\n\n"; }
45
46   //! Returns the thrown error message type.
47   virtual const Type& getType(void) const throw() { return type_; }
48
49   //! Returns the thrown error message string.
50   virtual const std::string& getMessage(void) const throw() { return message_; }
51
52   //! Returns the thrown error message as a c-style string.
53   virtual const char* what( void ) const throw() { return message_.c_str(); }
54
55  protected:
56   std::string message_;
57   Type type_;
58 };
59
60 #endif