annotate src/portaudio_20161030/bindings/cpp/include/portaudiocpp/Exception.hxx @ 81:7029a4916348

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