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