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