mkql_terminator.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "defs.h"
  2. #include "mkql_terminator.h"
  3. #include <yql/essentials/core/issue/yql_issue.h>
  4. #include <util/string/builder.h>
  5. namespace NKikimr {
  6. namespace NMiniKQL {
  7. TTerminateException::TTerminateException()
  8. : TErrorException(NYql::EYqlIssueCode::TIssuesIds_EIssueCode_CORE_RUNTIME_ERROR)
  9. {}
  10. thread_local ITerminator* TBindTerminator::Terminator = nullptr;
  11. TBindTerminator::TBindTerminator(ITerminator* terminator)
  12. : PreviousTerminator(Terminator)
  13. {
  14. Terminator = terminator;
  15. }
  16. TBindTerminator::~TBindTerminator()
  17. {
  18. Terminator = PreviousTerminator;
  19. }
  20. TThrowingBindTerminator::TThrowingBindTerminator()
  21. : TBindTerminator(this)
  22. {
  23. }
  24. void TThrowingBindTerminator::Terminate(const char* message) const {
  25. TStringBuf reason = (message ? TStringBuf(message) : TStringBuf("(unknown)"));
  26. TString fullMessage = TStringBuilder() <<
  27. "Terminate was called, reason(" << reason.size() << "): " << reason << Endl;
  28. ythrow TTerminateException() << fullMessage;
  29. }
  30. TOnlyThrowingBindTerminator::TOnlyThrowingBindTerminator()
  31. : TBindTerminator(this)
  32. {
  33. }
  34. void TOnlyThrowingBindTerminator::Terminate(const char* message) const {
  35. ythrow TTerminateException() << message;
  36. }
  37. [[noreturn]] void MKQLTerminate(const char* message) {
  38. if (const auto t = TBindTerminator::Terminator)
  39. t->Terminate(message);
  40. if (message)
  41. Cerr << message << Endl;
  42. ::abort();
  43. }
  44. }
  45. }