xref: /aosp_15_r20/external/flac/oss-fuzz/fuzzing/exception.hpp (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1 /* Copyright 2019 Guido Vranken
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject
9  * to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <exception>
27 #include <string>
28 
29 namespace fuzzing {
30 namespace exception {
31 
32 class ExceptionBase : public std::exception {
33     public:
34         ExceptionBase(void) = default;
35         /* typeid(T).name */
36 };
37 
38 /* Recoverable exception */
39 class FlowException : public ExceptionBase {
40     public:
FlowException(void)41         FlowException(void) : ExceptionBase() { }
42 };
43 
44 /* Error in this library, should never happen */
45 class LogicException : public ExceptionBase {
46     private:
47         std::string reason;
48     public:
LogicException(const std::string r)49         LogicException(const std::string r) : ExceptionBase(), reason(r) { }
what(void) const50         virtual const char* what(void) const throw() {
51             return reason.c_str();
52         }
53 };
54 
55 /* Error in target application */
56 class TargetException : public ExceptionBase {
57     private:
58         std::string reason;
59     public:
TargetException(const std::string r)60         TargetException(const std::string r) : ExceptionBase(), reason(r) { }
what(void) const61         virtual const char* what(void) const throw() {
62             return reason.c_str();
63         }
64 };
65 
66 } /* namespace exception */
67 } /* namespace fuzzing */
68