aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson_pull/exceptions.h
blob: 2d651990f89c32675f930fdfc5d6ee2e5b349f12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include "position_info.h"

#include <util/generic/string.h> 

#include <stdexcept>
#include <string>

namespace NYsonPull {
    namespace NException {
        class TBadStream: public std::exception {
            TString Message_; 
            TPositionInfo Position_;
            mutable TString FormattedMessage_; 

        public:
            TBadStream(
                TString message, 
                const TPositionInfo& position)
                : Message_(std::move(message))
                , Position_(position)
            {
            }

            const TPositionInfo& Position() const {
                return Position_;
            }

            const char* what() const noexcept override;
        };

        class TBadInput: public TBadStream {
        public:
            using TBadStream::TBadStream;
        };

        class TBadOutput: public TBadStream {
        public:
            using TBadStream::TBadStream;
        };

        class TSystemError: public std::exception {
            int SavedErrno_;

        public:
            TSystemError();
            TSystemError(int saved_errno)
                : SavedErrno_{saved_errno} {
            }

            int saved_errno() const noexcept {
                return SavedErrno_;
            }

            const char* what() const noexcept override;
        };
    }
}