alassert.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "alassert.h"
  2. #include <stdexcept>
  3. #include <string>
  4. namespace {
  5. [[noreturn]]
  6. void throw_error(const std::string &message)
  7. {
  8. throw std::runtime_error{message};
  9. }
  10. } /* namespace */
  11. namespace al {
  12. [[noreturn]]
  13. void do_assert(const char *message, int linenum, const char *filename, const char *funcname) noexcept
  14. {
  15. /* Throwing an exception that tries to leave a noexcept function will
  16. * hopefully cause the system to provide info about the caught exception in
  17. * an error dialog. At least on Linux, this results in the process printing
  18. *
  19. * terminate called after throwing an instance of 'std::runtime_error'
  20. * what(): <message here>
  21. *
  22. * before terminating from a SIGABRT. Hopefully Windows and Mac will do the
  23. * appropriate things with the message to alert the user about an abnormal
  24. * termination.
  25. */
  26. auto errstr = std::string{filename};
  27. errstr += ':';
  28. errstr += std::to_string(linenum);
  29. errstr += ": ";
  30. errstr += funcname;
  31. errstr += ": ";
  32. errstr += message;
  33. throw_error(errstr);
  34. }
  35. } /* namespace al */