You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovdAssert.h 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <exception>
  3. #include <stdexcept>
  4. #include <fs/Files.h>
  5. #include <openvibe/ovAssert.h>
  6. #include <openvibe/kernel/error/ovIErrorManager.h>
  7. #include <openvibe/kernel/error/ovIError.h>
  8. #define OV_ERROR_D(description, type, returnValue) OV_ERROR(description, type, returnValue, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  9. #define OV_ERROR_DRF(description, type) OV_ERROR(description, type, false, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  10. #define OV_ERROR_DRZ(description, type) OV_ERROR(description, type, 0, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  11. #define OV_ERROR_DRU(description, type) OV_ERROR(description, type, CIdentifier::undefined(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  12. #define OV_ERROR_DRV(description, type) OV_ERROR(description, type, void(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  13. #define OV_ERROR_DRN(description, type) OV_ERROR(description, type, nullptr, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  14. #define OV_ERROR_UNLESS_D(expression, description, type, returnValue) OV_ERROR_UNLESS(expression, description, type, returnValue, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  15. #define OV_ERROR_UNLESS_DRF(expression, description, type) OV_ERROR_UNLESS(expression, description, type, false, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  16. #define OV_ERROR_UNLESS_DRZ(expression, description, type) OV_ERROR_UNLESS(expression, description, type, 0, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  17. #define OV_ERROR_UNLESS_DRU(expression, description, type) OV_ERROR_UNLESS(expression, description, type, CIdentifier::undefined(), m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  18. #define OV_ERROR_UNLESS_DRV(expression, description, type) OV_ERROR_UNLESS(expression, description, type, void() , m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  19. #define OV_ERROR_UNLESS_DRN(expression, description, type) OV_ERROR_UNLESS(expression, description, type, nullptr, m_kernelCtx.getErrorManager(), m_kernelCtx.getLogManager())
  20. #define OV_FATAL_D(description, type) OV_FATAL(description, type, m_kernelCtx.getLogManager())
  21. #define OV_FATAL_UNLESS_D(expression, description, type) OV_FATAL_UNLESS(expression, description, type, m_kernelCtx.getLogManager())
  22. #ifndef _MSC_VER
  23. #define NOEXCEPT noexcept
  24. #else
  25. #define NOEXCEPT
  26. #endif
  27. class DesignerException final : public std::runtime_error
  28. {
  29. public:
  30. DesignerException(OpenViBE::Kernel::IErrorManager& errorManager)
  31. : std::runtime_error("Designer caused an exception"), m_ErrorManager(errorManager) {}
  32. const char* what() const NOEXCEPT override { return m_ErrorManager.getLastErrorString(); }
  33. std::string getErrorString() const
  34. {
  35. std::string errorMessage;
  36. const OpenViBE::Kernel::IError* error = m_ErrorManager.getLastError();
  37. while (error)
  38. {
  39. char location[1024];
  40. FS::Files::getFilename(error->getErrorLocation(), location);
  41. errorMessage += "Message: " + std::string(error->getErrorString()) + "\nFile: " + location + "\n";
  42. error = error->getNestedError();
  43. }
  44. m_ErrorManager.releaseErrors();
  45. return errorMessage;
  46. }
  47. void releaseErrors() NOEXCEPT { m_ErrorManager.releaseErrors(); }
  48. OpenViBE::Kernel::IErrorManager& m_ErrorManager;
  49. };
  50. #define OV_EXCEPTION_D(description, type) \
  51. do { \
  52. m_kernelCtx.getErrorManager().pushErrorAtLocation(type, static_cast<const OpenViBE::ErrorStream&>(OpenViBE::ErrorStream() << description).str().c_str(), __FILE__, __LINE__ ); \
  53. m_kernelCtx.getLogManager() << OpenViBE::Kernel::LogLevel_Fatal << "[Error description] = " << description << "; [Error code] = " << size_t((type)) << "\n"; \
  54. throw DesignerException(m_kernelCtx.getErrorManager()); \
  55. } while(0)
  56. #define OV_EXCEPTION_UNLESS_D(expression, description, type) \
  57. do { if (!(expression)) { OV_EXCEPTION_D(description, type); } } while(0)