1 #ifndef PROTOZERO_EXCEPTION_HPP
2 #define PROTOZERO_EXCEPTION_HPP
3 
4 /*****************************************************************************
5 
6 protozero - Minimalistic protocol buffer decoder and encoder in C++.
7 
8 This file is from https://github.com/mapbox/protozero where you can find more
9 documentation.
10 
11 *****************************************************************************/
12 
13 /**
14  * @file exception.hpp
15  *
16  * @brief Contains the exceptions used in the protozero library.
17  */
18 
19 #include <exception>
20 
21 /**
22  * @brief All parts of the protozero header-only library are in this namespace.
23  */
24 namespace protozero {
25 
26 /**
27  * All exceptions explicitly thrown by the functions of the protozero library
28  * derive from this exception.
29  */
30 struct exception : std::exception {
31     /// Returns the explanatory string.
whatprotozero::exception32     const char* what() const noexcept override { return "pbf exception"; }
33 };
34 
35 /**
36  * This exception is thrown when parsing a varint thats larger than allowed.
37  * This should never happen unless the data is corrupted.
38  */
39 struct varint_too_long_exception : exception {
40     /// Returns the explanatory string.
whatprotozero::varint_too_long_exception41     const char* what() const noexcept override { return "varint too long exception"; }
42 };
43 
44 /**
45  * This exception is thrown when the wire type of a pdf field is unknown.
46  * This should never happen unless the data is corrupted.
47  */
48 struct unknown_pbf_wire_type_exception : exception {
49     /// Returns the explanatory string.
whatprotozero::unknown_pbf_wire_type_exception50     const char* what() const noexcept override { return "unknown pbf field type exception"; }
51 };
52 
53 /**
54  * This exception is thrown when we are trying to read a field and there
55  * are not enough bytes left in the buffer to read it. Almost all functions
56  * of the pbf_reader class can throw this exception.
57  *
58  * This should never happen unless the data is corrupted or you have
59  * initialized the pbf_reader object with incomplete data.
60  */
61 struct end_of_buffer_exception : exception {
62     /// Returns the explanatory string.
whatprotozero::end_of_buffer_exception63     const char* what() const noexcept override { return "end of buffer exception"; }
64 };
65 
66 } // end namespace protozero
67 
68 #endif // PROTOZERO_EXCEPTION_HPP
69