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