summaryrefslogtreecommitdiff
path: root/RtError.h
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2013-10-09 23:46:54 +0200
committerStephen Sinclair <sinclair@music.mcgill.ca>2013-10-10 01:08:39 +0200
commit8cd04dd6b77f05fe0f032959dfefda58b2ce38ae (patch)
tree05ea4287636967811199897e9f6b23fedd87f946 /RtError.h
parent45906f9f72aaf6578431e68a06a0cdb0bf6ccec8 (diff)
Version 3.0
Diffstat (limited to 'RtError.h')
-rw-r--r--RtError.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/RtError.h b/RtError.h
new file mode 100644
index 0000000..465cd75
--- /dev/null
+++ b/RtError.h
@@ -0,0 +1,60 @@
+/************************************************************************/
+/*! \class RtError
+ \brief Exception handling class for RtAudio & RtMidi.
+
+ The RtError class is quite simple but it does allow errors to be
+ "caught" by RtError::Type. See the RtAudio and RtMidi
+ documentation to know which methods can throw an RtError.
+
+*/
+/************************************************************************/
+
+#ifndef RTERROR_H
+#define RTERROR_H
+
+#include <iostream>
+#include <string>
+
+class RtError
+{
+public:
+ //! Defined RtError types.
+ enum Type {
+ WARNING, /*!< A non-critical error. */
+ DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
+ UNSPECIFIED, /*!< The default, unspecified error type. */
+ NO_DEVICES_FOUND, /*!< No devices found on system. */
+ INVALID_DEVICE, /*!< An invalid device ID was specified. */
+ INVALID_STREAM, /*!< An invalid stream ID was specified. */
+ MEMORY_ERROR, /*!< An error occured during memory allocation. */
+ INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
+ DRIVER_ERROR, /*!< A system driver error occured. */
+ SYSTEM_ERROR, /*!< A system error occured. */
+ THREAD_ERROR /*!< A thread error occured. */
+ };
+
+protected:
+ std::string message_;
+ Type type_;
+
+public:
+ //! The constructor.
+ RtError(const std::string& message, Type type = RtError::UNSPECIFIED) : message_(message), type_(type){}
+
+ //! The destructor.
+ virtual ~RtError(void) {};
+
+ //! Prints thrown error message to stderr.
+ virtual void printMessage(void) { std::cerr << '\n' << message_ << "\n\n"; }
+
+ //! Returns the thrown error message type.
+ virtual const Type& getType(void) { return type_; }
+
+ //! Returns the thrown error message string.
+ virtual const std::string& getMessage(void) { return message_; }
+
+ //! Returns the thrown error message as a C string.
+ virtual const char *getMessageString(void) { return message_.c_str(); }
+};
+
+#endif