Chris@39: #ifndef INCLUDED_PORTAUDIO_EXCEPTION_HXX Chris@39: #define INCLUDED_PORTAUDIO_EXCEPTION_HXX Chris@39: Chris@39: // --------------------------------------------------------------------------------------- Chris@39: Chris@39: #include Chris@39: Chris@39: #include "portaudio.h" Chris@39: Chris@39: // --------------------------------------------------------------------------------------- Chris@39: Chris@39: namespace portaudio Chris@39: { Chris@39: Chris@39: ////// Chris@39: /// @brief Base class for all exceptions PortAudioCpp can throw. Chris@39: /// Chris@39: /// Class is derived from std::exception. Chris@39: ////// Chris@39: class Exception : public std::exception Chris@39: { Chris@39: public: Chris@39: virtual ~Exception() throw() {} Chris@39: Chris@39: virtual const char *what() const throw() = 0; Chris@39: }; Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// @brief Wrapper for PortAudio error codes to C++ exceptions. Chris@39: /// Chris@39: /// It wraps up PortAudio's error handling mechanism using Chris@39: /// C++ exceptions and is derived from std::exception for Chris@39: /// easy exception handling and to ease integration with Chris@39: /// other code. Chris@39: /// Chris@39: /// To know what exceptions each function may throw, look up Chris@39: /// the errors that can occure in the PortAudio documentation Chris@39: /// for the equivalent functions. Chris@39: /// Chris@39: /// Some functions are likely to throw an exception (such as Chris@39: /// Stream::open(), etc) and these should always be called in Chris@39: /// try{} catch{} blocks and the thrown exceptions should be Chris@39: /// handled properly (ie. the application shouldn't just abort, Chris@39: /// but merely display a warning dialog to the user or something). Chris@39: /// However nearly all functions in PortAudioCpp are capable Chris@39: /// of throwing exceptions. When a function like Stream::isStopped() Chris@39: /// throws an exception, it's such an exceptional state that it's Chris@39: /// not likely that it can be recovered. PaExceptions such as these Chris@39: /// can ``safely'' be left to be handled by some outer catch-all-like Chris@39: /// mechanism for unrecoverable errors. Chris@39: ////// Chris@39: class PaException : public Exception Chris@39: { Chris@39: public: Chris@39: explicit PaException(PaError error); Chris@39: Chris@39: const char *what() const throw(); Chris@39: Chris@39: PaError paError() const; Chris@39: const char *paErrorText() const; Chris@39: Chris@39: bool isHostApiError() const; // extended Chris@39: long lastHostApiError() const; Chris@39: const char *lastHostApiErrorText() const; Chris@39: Chris@39: bool operator==(const PaException &rhs) const; Chris@39: bool operator!=(const PaException &rhs) const; Chris@39: Chris@39: private: Chris@39: PaError error_; Chris@39: }; Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an Chris@39: /// equivalent PortAudio error code). Chris@39: ////// Chris@39: class PaCppException : public Exception Chris@39: { Chris@39: public: Chris@39: enum ExceptionSpecifier Chris@39: { Chris@39: UNABLE_TO_ADAPT_DEVICE Chris@39: }; Chris@39: Chris@39: PaCppException(ExceptionSpecifier specifier); Chris@39: Chris@39: const char *what() const throw(); Chris@39: Chris@39: ExceptionSpecifier specifier() const; Chris@39: Chris@39: bool operator==(const PaCppException &rhs) const; Chris@39: bool operator!=(const PaCppException &rhs) const; Chris@39: Chris@39: private: Chris@39: ExceptionSpecifier specifier_; Chris@39: }; Chris@39: Chris@39: Chris@39: } // namespace portaudio Chris@39: Chris@39: // --------------------------------------------------------------------------------------- Chris@39: Chris@39: #endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX Chris@39: