exception.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #pragma once
  24. #include <exception>
  25. #include <string>
  26. namespace fuzzing {
  27. namespace exception {
  28. class ExceptionBase : public std::exception {
  29. public:
  30. ExceptionBase(void) = default;
  31. /* typeid(T).name */
  32. };
  33. /* Recoverable exception */
  34. class FlowException : public ExceptionBase {
  35. public:
  36. FlowException(void) : ExceptionBase() { }
  37. };
  38. /* Error in this library, should never happen */
  39. class LogicException : public ExceptionBase {
  40. private:
  41. std::string reason;
  42. public:
  43. LogicException(const std::string r) : ExceptionBase(), reason(r) { }
  44. virtual const char* what(void) const throw() {
  45. return reason.c_str();
  46. }
  47. };
  48. /* Error in target application */
  49. class TargetException : public ExceptionBase {
  50. private:
  51. std::string reason;
  52. public:
  53. TargetException(const std::string r) : ExceptionBase(), reason(r) { }
  54. virtual const char* what(void) const throw() {
  55. return reason.c_str();
  56. }
  57. };
  58. } /* namespace exception */
  59. } /* namespace fuzzing */