]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/Exceptions.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / Exceptions.h
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #pragma once
7
8 #include "antlr4-common.h"
9
10 namespace antlr4 {
11
12   // An exception hierarchy modelled loosely after java.lang.* exceptions.
13   class ANTLR4CPP_PUBLIC RuntimeException : public std::exception {
14   private:
15     std::string _message;
16   public:
17     RuntimeException(const std::string &msg = "");
18
19     virtual const char* what() const NOEXCEPT override;
20   };
21
22   class ANTLR4CPP_PUBLIC IllegalStateException : public RuntimeException {
23   public:
24     IllegalStateException(const std::string &msg = "") : RuntimeException(msg) {}
25     IllegalStateException(IllegalStateException const&) = default;
26     ~IllegalStateException();
27     IllegalStateException& operator=(IllegalStateException const&) = default;
28   };
29
30   class ANTLR4CPP_PUBLIC IllegalArgumentException : public RuntimeException {
31   public:
32     IllegalArgumentException(IllegalArgumentException const&) = default;
33     IllegalArgumentException(const std::string &msg = "") : RuntimeException(msg) {}
34     ~IllegalArgumentException();
35     IllegalArgumentException& operator=(IllegalArgumentException const&) = default;
36   };
37
38   class ANTLR4CPP_PUBLIC NullPointerException : public RuntimeException {
39   public:
40     NullPointerException(const std::string &msg = "") : RuntimeException(msg) {}
41     NullPointerException(NullPointerException const&) = default;
42     ~NullPointerException();
43     NullPointerException& operator=(NullPointerException const&) = default;
44   };
45
46   class ANTLR4CPP_PUBLIC IndexOutOfBoundsException : public RuntimeException {
47   public:
48     IndexOutOfBoundsException(const std::string &msg = "") : RuntimeException(msg) {}
49     IndexOutOfBoundsException(IndexOutOfBoundsException const&) = default;
50     ~IndexOutOfBoundsException();
51     IndexOutOfBoundsException& operator=(IndexOutOfBoundsException const&) = default;
52   };
53
54   class ANTLR4CPP_PUBLIC UnsupportedOperationException : public RuntimeException {
55   public:
56     UnsupportedOperationException(const std::string &msg = "") : RuntimeException(msg) {}
57     UnsupportedOperationException(UnsupportedOperationException const&) = default;
58     ~UnsupportedOperationException();
59     UnsupportedOperationException& operator=(UnsupportedOperationException const&) = default;
60
61   };
62
63   class ANTLR4CPP_PUBLIC EmptyStackException : public RuntimeException {
64   public:
65     EmptyStackException(const std::string &msg = "") : RuntimeException(msg) {}
66     EmptyStackException(EmptyStackException const&) = default;
67     ~EmptyStackException();
68     EmptyStackException& operator=(EmptyStackException const&) = default;
69   };
70
71   // IOException is not a runtime exception (in the java hierarchy).
72   // Hence we have to duplicate the RuntimeException implementation.
73   class ANTLR4CPP_PUBLIC IOException : public std::exception {
74   private:
75     std::string _message;
76
77   public:
78     IOException(const std::string &msg = "");
79
80     virtual const char* what() const NOEXCEPT override;
81   };
82
83   class ANTLR4CPP_PUBLIC CancellationException : public IllegalStateException {
84   public:
85     CancellationException(const std::string &msg = "") : IllegalStateException(msg) {}
86     CancellationException(CancellationException const&) = default;
87     ~CancellationException();
88     CancellationException& operator=(CancellationException const&) = default;
89   };
90
91   class ANTLR4CPP_PUBLIC ParseCancellationException : public CancellationException {
92   public:
93     ParseCancellationException(const std::string &msg = "") : CancellationException(msg) {}
94     ParseCancellationException(ParseCancellationException const&) = default;
95     ~ParseCancellationException();
96     ParseCancellationException& operator=(ParseCancellationException const&) = default;
97   };
98
99 } // namespace antlr4