summaryrefslogtreecommitdiff
path: root/3rdparty/portaudio/bindings/cpp/include/portaudiocpp/Exception.hxx
blob: 02d36b213f0bc756ec053620a714dcff73334e1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef INCLUDED_PORTAUDIO_EXCEPTION_HXX
#define INCLUDED_PORTAUDIO_EXCEPTION_HXX

// ---------------------------------------------------------------------------------------

#include <exception>

#include "portaudio.h"

// ---------------------------------------------------------------------------------------

namespace portaudio
{

	//////
	/// @brief Base class for all exceptions PortAudioCpp can throw.
	///
	/// Class is derived from std::exception.
	//////
	class Exception : public std::exception
	{
	public:
		virtual ~Exception() throw() {}

		virtual const char *what() const throw() = 0;
	};
	
	// -----------------------------------------------------------------------------------

	//////
	/// @brief Wrapper for PortAudio error codes to C++ exceptions.
	///
	/// It wraps up PortAudio's error handling mechanism using 
	/// C++ exceptions and is derived from std::exception for 
	/// easy exception handling and to ease integration with 
	/// other code.
	///
	/// To know what exceptions each function may throw, look up 
	/// the errors that can occur in the PortAudio documentation 
	/// for the equivalent functions.
	///
	/// Some functions are likely to throw an exception (such as 
	/// Stream::open(), etc) and these should always be called in 
	/// try{} catch{} blocks and the thrown exceptions should be 
	/// handled properly (ie. the application shouldn't just abort, 
	/// but merely display a warning dialog to the user or something).
	/// However nearly all functions in PortAudioCpp are capable 
	/// of throwing exceptions. When a function like Stream::isStopped() 
	/// throws an exception, it's such an exceptional state that it's 
	/// not likely that it can be recovered. PaExceptions such as these 
	/// can ``safely'' be left to be handled by some outer catch-all-like 
	/// mechanism for unrecoverable errors.
	//////
	class PaException : public Exception
	{
	public:
		explicit PaException(PaError error);

		const char *what() const throw();

		PaError paError() const;
		const char *paErrorText() const;

		bool isHostApiError() const; // extended
		long lastHostApiError() const;
		const char *lastHostApiErrorText() const;

		bool operator==(const PaException &rhs) const;
		bool operator!=(const PaException &rhs) const;

	private:
		PaError error_;
 	};

	// -----------------------------------------------------------------------------------

	//////
	/// @brief Exceptions specific to PortAudioCpp (ie. exceptions which do not have an 
	/// equivalent PortAudio error code).
	//////
	class PaCppException : public Exception
	{
	public:
		enum ExceptionSpecifier
		{
			UNABLE_TO_ADAPT_DEVICE
		};

		PaCppException(ExceptionSpecifier specifier);

		const char *what() const throw();

		ExceptionSpecifier specifier() const;

		bool operator==(const PaCppException &rhs) const;
		bool operator!=(const PaCppException &rhs) const;

	private:
		ExceptionSpecifier specifier_;
	};


} // namespace portaudio

// ---------------------------------------------------------------------------------------

#endif // INCLUDED_PORTAUDIO_EXCEPTION_HXX