annotate src/portaudio_20140130/bindings/cpp/include/portaudiocpp/Exception.hxx @ 39:7ddb4fc30dac

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