alassert.cpp 1019 B

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