comparison data/midi/rtmidi/RtError.h @ 559:32d156c75df7

* midi stubs (this revision will not compile)
author Chris Cannam
date Mon, 23 Feb 2009 11:41:28 +0000
parents
children
comparison
equal deleted inserted replaced
558:1d7ebc05157e 559:32d156c75df7
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 <iostream>
16 #include <string>
17
18 class RtError
19 {
20 public:
21 //! Defined RtError types.
22 enum Type {
23 WARNING, /*!< A non-critical error. */
24 DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
25 UNSPECIFIED, /*!< The default, unspecified error type. */
26 NO_DEVICES_FOUND, /*!< No devices found on system. */
27 INVALID_DEVICE, /*!< An invalid device ID was specified. */
28 INVALID_STREAM, /*!< An invalid stream ID was specified. */
29 MEMORY_ERROR, /*!< An error occured during memory allocation. */
30 INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
31 DRIVER_ERROR, /*!< A system driver error occured. */
32 SYSTEM_ERROR, /*!< A system error occured. */
33 THREAD_ERROR /*!< A thread error occured. */
34 };
35
36 protected:
37 std::string message_;
38 Type type_;
39
40 public:
41 //! The constructor.
42 RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type) {}
43
44 //! The destructor.
45 virtual ~RtError(void) {};
46
47 //! Prints thrown error message to stderr.
48 virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; }
49
50 //! Returns the thrown error message type.
51 virtual const Type& getType(void) { return type_; }
52
53 //! Returns the thrown error message string.
54 virtual const std::string& getMessage(void) { return message_; }
55
56 //! Returns the thrown error message as a C string.
57 virtual const char *getMessageString(void) { return message_.c_str(); }
58 };
59
60 #endif