exceptions.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "exceptions.h"
  2. #include <util/string/builder.h>
  3. #include <cerrno>
  4. #include <cstring>
  5. using namespace NYsonPull::NException;
  6. const char* TBadStream::what() const noexcept {
  7. TStringBuilder stream;
  8. stream << "Invalid YSON";
  9. if (Position_.Offset || Position_.Line || Position_.Column) {
  10. bool first = true;
  11. stream << " at ";
  12. if (Position_.Offset) {
  13. stream << "offset " << *Position_.Offset;
  14. first = false;
  15. }
  16. if (Position_.Line) {
  17. if (!first) {
  18. stream << ", ";
  19. }
  20. stream << "line " << *Position_.Line;
  21. first = false;
  22. }
  23. if (Position_.Column) {
  24. if (!first) {
  25. stream << ", ";
  26. }
  27. stream << "column " << *Position_.Column;
  28. }
  29. }
  30. stream << ": " << Message_;
  31. FormattedMessage_ = stream;
  32. return FormattedMessage_.c_str();
  33. }
  34. NYsonPull::NException::TSystemError::TSystemError()
  35. : SavedErrno_{errno} {
  36. }
  37. const char* NYsonPull::NException::TSystemError::what() const noexcept {
  38. return ::strerror(SavedErrno_);
  39. }