mkql_terminator.cpp 1.2 KB

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