Exception.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * \def AUD_NOEXCEPT
  19. * Compatibility macro for noexcept.
  20. */
  21. #ifdef _MSC_VER
  22. #define AUD_NOEXCEPT
  23. #else
  24. #define AUD_NOEXCEPT noexcept
  25. #endif
  26. /**
  27. * @file Exception.h
  28. * @ingroup general
  29. * Defines the Exception class as well as the AUD_THROW macro for easy throwing.
  30. */
  31. #include "Audaspace.h"
  32. #include <exception>
  33. #include <string>
  34. /// Throws a Exception with the provided error code.
  35. #define AUD_THROW(exception, message) { throw exception(message, __FILE__, __LINE__); }
  36. AUD_NAMESPACE_BEGIN
  37. /**
  38. * The Exception class is the general exception base class.
  39. */
  40. class AUD_API Exception : public std::exception
  41. {
  42. protected:
  43. /// A message describing the problem.
  44. const std::string m_message;
  45. /// The source code file in which the exception was thrown.
  46. const std::string m_file;
  47. /// The source code line from which the exception was thrown.
  48. const int m_line;
  49. /**
  50. * Copy constructor.
  51. * @param exception The exception to be copied.
  52. */
  53. Exception(const Exception& exception);
  54. /**
  55. * Creates a new Exception object.
  56. * @param message A message describing the problem.
  57. * @param file The source code file in which the exception was thrown.
  58. * @param line The source code line from which the exception was thrown.
  59. */
  60. Exception(std::string message, std::string file, int line);
  61. public:
  62. /**
  63. * Destroys the object.
  64. */
  65. virtual ~Exception() AUD_NOEXCEPT;
  66. /**
  67. * Returns the error message.
  68. * @return A C string error message.
  69. */
  70. virtual const char* what() const AUD_NOEXCEPT;
  71. /**
  72. * Returns the error message plus file and line number for debugging purposes.
  73. * @return The error message including debug information.
  74. */
  75. virtual std::string getDebugMessage() const;
  76. /**
  77. * Returns the error message.
  78. * @return The error message as string.
  79. */
  80. const std::string& getMessage() const;
  81. /**
  82. * Returns the file in which the exception was thrown.
  83. * @return The name of the file in which the exception was thrown.
  84. */
  85. const std::string& getFile() const;
  86. /**
  87. * Returns the line where the exception was originally thrown.
  88. * @return The line of the source file where the exception was generated.
  89. */
  90. int getLine() const;
  91. };
  92. /**
  93. * The FileException class is used for error cases in which files cannot
  94. * be read or written due to unknown containers or codecs.
  95. */
  96. class AUD_API FileException : public Exception
  97. {
  98. public:
  99. /**
  100. * Creates a new FileException object.
  101. * @param message A message describing the problem.
  102. * @param file The source code file in which the exception was thrown.
  103. * @param line The source code line from which the exception was thrown.
  104. */
  105. FileException(std::string message, std::string file, int line);
  106. /**
  107. * Copy constructor.
  108. * @param exception The exception to be copied.
  109. */
  110. FileException(const FileException& exception);
  111. ~FileException() AUD_NOEXCEPT;
  112. };
  113. /**
  114. * The DeviceException class is used for error cases in connection with
  115. * devices, which usually happens when specific features or requests
  116. * cannot be fulfilled by a device, for example when the device is opened.
  117. */
  118. class AUD_API DeviceException : public Exception
  119. {
  120. public:
  121. /**
  122. * Creates a new DeviceException object.
  123. * @param message A message describing the problem.
  124. * @param file The source code file in which the exception was thrown.
  125. * @param line The source code line from which the exception was thrown.
  126. */
  127. DeviceException(std::string message, std::string file, int line);
  128. /**
  129. * Copy constructor.
  130. * @param exception The exception to be copied.
  131. */
  132. DeviceException(const DeviceException& exception);
  133. ~DeviceException() AUD_NOEXCEPT;
  134. };
  135. /**
  136. * The StateException class is used for error cases of sounds or readers
  137. * with illegal states or requirements for states of dependent classes.
  138. * It is used for example when an effect reader needs a specific
  139. * specification from its input.
  140. */
  141. class AUD_API StateException : public Exception
  142. {
  143. public:
  144. /**
  145. * Creates a new StateException object.
  146. * @param message A message describing the problem.
  147. * @param file The source code file in which the exception was thrown.
  148. * @param line The source code line from which the exception was thrown.
  149. */
  150. StateException(std::string message, std::string file, int line);
  151. /**
  152. * Copy constructor.
  153. * @param exception The exception to be copied.
  154. */
  155. StateException(const StateException& exception);
  156. ~StateException() AUD_NOEXCEPT;
  157. };
  158. AUD_NAMESPACE_END