error.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2012-2018 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "core/types.h"
  7. /// @defgroup Error Error
  8. /// @ingroup Core
  9. namespace crown
  10. {
  11. /// Error management.
  12. ///
  13. /// @ingroup Error
  14. namespace error
  15. {
  16. /// Aborts the program execution logging an error message and the stacktrace if
  17. /// the platform supports it.
  18. void abort(const char* format, ...);
  19. } // namespace error
  20. } // namespace crown
  21. #if CROWN_DEBUG
  22. #define CE_ASSERT(condition, msg, ...) \
  23. do \
  24. { \
  25. if (CE_UNLIKELY(!(condition))) \
  26. { \
  27. crown::error::abort("Assertion failed: %s\n" \
  28. " In: %s:%d\n" \
  29. " " msg "\n" \
  30. , # condition \
  31. , __FILE__ \
  32. , __LINE__ \
  33. , ## __VA_ARGS__ \
  34. ); \
  35. } \
  36. } while (0)
  37. #else
  38. #define CE_ASSERT(...) CE_NOOP()
  39. #endif // CROWN_DEBUG
  40. #define CE_FATAL(msg, ...) CE_ASSERT(false, msg, ## __VA_ARGS__)
  41. #define CE_ENSURE(condition) CE_ASSERT(condition, "")