annotate src/portaudio_20161030/bindings/cpp/include/portaudiocpp/Exception.hxx @ 140:59a8758c56b1

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