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