Skip to content

Add a deserialization exception #2954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/util/exception_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Author: Fotis Koutoulakis, [email protected]

#include "exception_utils.h"

#include <utility>

std::string invalid_user_input_exceptiont::what() const noexcept
{
std::string res;
Expand All @@ -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;
}
28 changes: 28 additions & 0 deletions src/util/exception_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,32 @@ 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;
}
};

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
11 changes: 11 additions & 0 deletions src/util/parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ 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;
}
catch (const deserialization_exceptiont &e)
{
std::cerr << e.what() << '\n';
return CPROVER_EXIT_EXCEPTION;
}

return CPROVER_EXIT_SUCCESS;
}

Expand Down