1 #ifndef INCLUDED_PORTAUDIO_EXCEPTION_HXX
\r
2 #define INCLUDED_PORTAUDIO_EXCEPTION_HXX
\r
4 // ---------------------------------------------------------------------------------------
\r
8 #include "portaudio.h"
\r
10 // ---------------------------------------------------------------------------------------
\r
16 /// @brief Base class for all exceptions PortAudioCpp can throw.
\r
18 /// Class is derived from std::exception.
\r
20 class Exception : public std::exception
\r
23 virtual ~Exception() throw() {}
\r
25 virtual const char *what() const throw() = 0;
\r
28 // -----------------------------------------------------------------------------------
\r
31 /// @brief Wrapper for PortAudio error codes to C++ exceptions.
\r
33 /// It wraps up PortAudio's error handling mechanism using
\r
34 /// C++ exceptions and is derived from std::exception for
\r
35 /// easy exception handling and to ease integration with
\r
38 /// To know what exceptions each function may throw, look up
\r
39 /// the errors that can occure in the PortAudio documentation
\r
40 /// for the equivalent functions.
\r
42 /// Some functions are likely to throw an exception (such as
\r
43 /// Stream::open(), etc) and these should always be called in
\r
44 /// try{} catch{} blocks and the thrown exceptions should be
\r
45 /// handled properly (ie. the application shouldn't just abort,
\r
46 /// but merely display a warning dialog to the user or something).
\r
47 /// However nearly all functions in PortAudioCpp are capable
\r
48 /// of throwing exceptions. When a function like Stream::isStopped()
\r
49 /// throws an exception, it's such an exceptional state that it's
\r
50 /// not likely that it can be recovered. PaExceptions such as these
\r
51 /// can ``safely'' be left to be handled by some outer catch-all-like
\r
52 /// mechanism for unrecoverable errors.
\r
54 class PaException : public Exception
\r
57 explicit PaException(PaError error);
\r
59 const char *what() const throw();
\r
61 PaError paError() const;
\r
62 const char *paErrorText() const;
\r
64 bool isHostApiError() const; // extended
\r
65 long lastHostApiError() const;
\r
66 const char *lastHostApiErrorText() const;
\r
68 bool operator==(const PaException &rhs) const;
\r
69 bool operator!=(const PaException &rhs) const;
\r
75 // -----------------------------------------------------------------------------------
\r
78 /// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an
\r
79 /// equivalent PortAudio error code).
\r
81 class PaCppException : public Exception
\r
84 enum ExceptionSpecifier
\r
86 UNABLE_TO_ADAPT_DEVICE
\r
89 PaCppException(ExceptionSpecifier specifier);
\r
91 const char *what() const throw();
\r
93 ExceptionSpecifier specifier() const;
\r
95 bool operator==(const PaCppException &rhs) const;
\r
96 bool operator!=(const PaCppException &rhs) const;
\r
99 ExceptionSpecifier specifier_;
\r
103 } // namespace portaudio
\r
105 // ---------------------------------------------------------------------------------------
\r
107 #endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX
\r