annotate src/portaudio_20140130/bindings/cpp/include/portaudiocpp/Exception.hxx @ 169:223a55898ab9 tip default

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