summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/exception.h
blob: b5141cb4c27f44ed0bc6d6a13721af6f5145e5c0 (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
#ifndef AUDIOGRAPHER_EXCEPTION_H
#define AUDIOGRAPHER_EXCEPTION_H

#include <exception>
#include <string>

#include <boost/format.hpp>

#include "audiographer/visibility.h"
#include "audiographer/debug_utils.h"

namespace AudioGrapher
{

/** AudioGrapher Exception class.
  * Automatically tells which class an exception was thrown from.
  */
class LIBAUDIOGRAPHER_API Exception : public std::exception
{
  public:
	template<typename T>
	Exception (T const & thrower, std::string const & reason)
	  : reason (boost::str (boost::format
			("Exception thrown by %1%: %2%")
			% DebugUtils::demangled_name (thrower) % reason))
	{}

	virtual ~Exception () throw() { }

	const char* what() const throw()
	{
		return reason.c_str();
	}

  private:
	std::string const reason;

};

} // namespace AudioGrapher

#endif // AUDIOGRAPHER_EXCEPTION_H