From 8aa3d1976dc60f731c956c68a2bce4923c7623a6 Mon Sep 17 00:00:00 2001 From: Daniel Poetzl Date: Thu, 16 Aug 2018 16:56:00 +0100 Subject: [PATCH 1/2] Add system exception for os-related error --- src/util/exception_utils.h | 19 +++++++++++++++++++ src/util/parse_options.cpp | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/util/exception_utils.h b/src/util/exception_utils.h index 4c871b94fbf..4a9361a1dbd 100644 --- a/src/util/exception_utils.h +++ b/src/util/exception_utils.h @@ -33,4 +33,23 @@ class invalid_user_input_exceptiont std::string what() const noexcept; }; +class system_exceptiont +{ +private: + std::string reason; + +public: + system_exceptiont(const std::string &reason) : reason(reason) + { + } + + std::string what() const noexcept + { + std::string res; + res += "System Exception\n"; + res += "Reason: " + reason + "\n"; + return res; + } +}; + #endif // CPROVER_UTIL_EXCEPTION_UTILS_H diff --git a/src/util/parse_options.cpp b/src/util/parse_options.cpp index b5a1b7e9b1f..767b8e8045e 100644 --- a/src/util/parse_options.cpp +++ b/src/util/parse_options.cpp @@ -76,6 +76,12 @@ int parse_options_baset::main() std::cerr << e.what() << "\n"; return CPROVER_EXIT_USAGE_ERROR; } + catch(system_exceptiont &e) + { + std::cerr << e.what() << "\n"; + return CPROVER_EXIT_EXCEPTION; + } + return CPROVER_EXIT_SUCCESS; } From ff90f53cedc8a9edb9ea9c66b071d18229ab2efd Mon Sep 17 00:00:00 2001 From: Hannes Steffenhagen Date: Fri, 14 Sep 2018 13:41:38 +0100 Subject: [PATCH 2/2] Add deserialization exception class --- src/util/exception_utils.cpp | 10 ++++++++++ src/util/exception_utils.h | 9 +++++++++ src/util/parse_options.cpp | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/util/exception_utils.cpp b/src/util/exception_utils.cpp index 148ddc742cd..8db0baedeed 100644 --- a/src/util/exception_utils.cpp +++ b/src/util/exception_utils.cpp @@ -8,6 +8,8 @@ Author: Fotis Koutoulakis, fotis.koutoulakis@diffblue.com #include "exception_utils.h" +#include + std::string invalid_user_input_exceptiont::what() const noexcept { std::string res; @@ -18,3 +20,11 @@ std::string invalid_user_input_exceptiont::what() const noexcept res += correct_input + "\n"; return res; } + +deserialization_exceptiont::deserialization_exceptiont(std::string message) + : message(std::move(message)) +{} + +std::string deserialization_exceptiont::what() const noexcept { + return message; +} diff --git a/src/util/exception_utils.h b/src/util/exception_utils.h index 4a9361a1dbd..b6ae1b54097 100644 --- a/src/util/exception_utils.h +++ b/src/util/exception_utils.h @@ -52,4 +52,13 @@ class system_exceptiont } }; +class deserialization_exceptiont +{ +public: + explicit deserialization_exceptiont(std::string message); + std::string what() const noexcept; +private: + std::string message; +}; + #endif // CPROVER_UTIL_EXCEPTION_UTILS_H diff --git a/src/util/parse_options.cpp b/src/util/parse_options.cpp index 767b8e8045e..e27a4a39e6e 100644 --- a/src/util/parse_options.cpp +++ b/src/util/parse_options.cpp @@ -81,6 +81,11 @@ int parse_options_baset::main() std::cerr << e.what() << "\n"; return CPROVER_EXIT_EXCEPTION; } + catch (const deserialization_exceptiont &e) + { + std::cerr << e.what() << '\n'; + return CPROVER_EXIT_EXCEPTION; + } return CPROVER_EXIT_SUCCESS; }