annotate src/portaudio/bindings/cpp/include/portaudiocpp/Exception.hxx @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents e13257ea84a4
children
rev   line source
Chris@4 1 #ifndef INCLUDED_PORTAUDIO_EXCEPTION_HXX
Chris@4 2 #define INCLUDED_PORTAUDIO_EXCEPTION_HXX
Chris@4 3
Chris@4 4 // ---------------------------------------------------------------------------------------
Chris@4 5
Chris@4 6 #include <exception>
Chris@4 7
Chris@4 8 #include "portaudio.h"
Chris@4 9
Chris@4 10 // ---------------------------------------------------------------------------------------
Chris@4 11
Chris@4 12 namespace portaudio
Chris@4 13 {
Chris@4 14
Chris@4 15 //////
Chris@4 16 /// @brief Base class for all exceptions PortAudioCpp can throw.
Chris@4 17 ///
Chris@4 18 /// Class is derived from std::exception.
Chris@4 19 //////
Chris@4 20 class Exception : public std::exception
Chris@4 21 {
Chris@4 22 public:
Chris@4 23 virtual ~Exception() throw() {}
Chris@4 24
Chris@4 25 virtual const char *what() const throw() = 0;
Chris@4 26 };
Chris@4 27
Chris@4 28 // -----------------------------------------------------------------------------------
Chris@4 29
Chris@4 30 //////
Chris@4 31 /// @brief Wrapper for PortAudio error codes to C++ exceptions.
Chris@4 32 ///
Chris@4 33 /// It wraps up PortAudio's error handling mechanism using
Chris@4 34 /// C++ exceptions and is derived from std::exception for
Chris@4 35 /// easy exception handling and to ease integration with
Chris@4 36 /// other code.
Chris@4 37 ///
Chris@4 38 /// To know what exceptions each function may throw, look up
Chris@4 39 /// the errors that can occure in the PortAudio documentation
Chris@4 40 /// for the equivalent functions.
Chris@4 41 ///
Chris@4 42 /// Some functions are likely to throw an exception (such as
Chris@4 43 /// Stream::open(), etc) and these should always be called in
Chris@4 44 /// try{} catch{} blocks and the thrown exceptions should be
Chris@4 45 /// handled properly (ie. the application shouldn't just abort,
Chris@4 46 /// but merely display a warning dialog to the user or something).
Chris@4 47 /// However nearly all functions in PortAudioCpp are capable
Chris@4 48 /// of throwing exceptions. When a function like Stream::isStopped()
Chris@4 49 /// throws an exception, it's such an exceptional state that it's
Chris@4 50 /// not likely that it can be recovered. PaExceptions such as these
Chris@4 51 /// can ``safely'' be left to be handled by some outer catch-all-like
Chris@4 52 /// mechanism for unrecoverable errors.
Chris@4 53 //////
Chris@4 54 class PaException : public Exception
Chris@4 55 {
Chris@4 56 public:
Chris@4 57 explicit PaException(PaError error);
Chris@4 58
Chris@4 59 const char *what() const throw();
Chris@4 60
Chris@4 61 PaError paError() const;
Chris@4 62 const char *paErrorText() const;
Chris@4 63
Chris@4 64 bool isHostApiError() const; // extended
Chris@4 65 long lastHostApiError() const;
Chris@4 66 const char *lastHostApiErrorText() const;
Chris@4 67
Chris@4 68 bool operator==(const PaException &rhs) const;
Chris@4 69 bool operator!=(const PaException &rhs) const;
Chris@4 70
Chris@4 71 private:
Chris@4 72 PaError error_;
Chris@4 73 };
Chris@4 74
Chris@4 75 // -----------------------------------------------------------------------------------
Chris@4 76
Chris@4 77 //////
Chris@4 78 /// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an
Chris@4 79 /// equivalent PortAudio error code).
Chris@4 80 //////
Chris@4 81 class PaCppException : public Exception
Chris@4 82 {
Chris@4 83 public:
Chris@4 84 enum ExceptionSpecifier
Chris@4 85 {
Chris@4 86 UNABLE_TO_ADAPT_DEVICE
Chris@4 87 };
Chris@4 88
Chris@4 89 PaCppException(ExceptionSpecifier specifier);
Chris@4 90
Chris@4 91 const char *what() const throw();
Chris@4 92
Chris@4 93 ExceptionSpecifier specifier() const;
Chris@4 94
Chris@4 95 bool operator==(const PaCppException &rhs) const;
Chris@4 96 bool operator!=(const PaCppException &rhs) const;
Chris@4 97
Chris@4 98 private:
Chris@4 99 ExceptionSpecifier specifier_;
Chris@4 100 };
Chris@4 101
Chris@4 102
Chris@4 103 } // namespace portaudio
Chris@4 104
Chris@4 105 // ---------------------------------------------------------------------------------------
Chris@4 106
Chris@4 107 #endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX
Chris@4 108