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