exceptions.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "position_info.h"
  3. #include <util/generic/string.h>
  4. #include <stdexcept>
  5. #include <string>
  6. namespace NYsonPull {
  7. namespace NException {
  8. class TBadStream: public std::exception {
  9. TString Message_;
  10. TPositionInfo Position_;
  11. mutable TString FormattedMessage_;
  12. public:
  13. TBadStream(
  14. TString message,
  15. const TPositionInfo& position)
  16. : Message_(std::move(message))
  17. , Position_(position)
  18. {
  19. }
  20. const TPositionInfo& Position() const {
  21. return Position_;
  22. }
  23. const char* what() const noexcept override;
  24. };
  25. class TBadInput: public TBadStream {
  26. public:
  27. using TBadStream::TBadStream;
  28. };
  29. class TBadOutput: public TBadStream {
  30. public:
  31. using TBadStream::TBadStream;
  32. };
  33. class TSystemError: public std::exception {
  34. int SavedErrno_;
  35. public:
  36. TSystemError();
  37. TSystemError(int saved_errno)
  38. : SavedErrno_{saved_errno} {
  39. }
  40. int saved_errno() const noexcept {
  41. return SavedErrno_;
  42. }
  43. const char* what() const noexcept override;
  44. };
  45. }
  46. }