annotate src/portaudio/bindings/cpp/include/portaudiocpp/Exception.hxx @ 105:c83a7e2af39c

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