CBMC
exception_utils.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Exception helper utilities
4 
5 Author: Fotis Koutoulakis, fotis.koutoulakis@diffblue.com
6 
7 \*******************************************************************/
8 
9 #include "exception_utils.h"
10 #include <utility>
11 
12 std::string cprover_exception_baset::what() const
13 {
14  return reason;
15 }
16 
18 {
19  std::string res;
20  res += "Invalid User Input";
21  res += "\nOption: " + option;
22  res += "\nReason: " + reason;
23  // Print an optional correct usage message assuming correct input parameters have been passed
24  if(!correct_input.empty())
25  {
26  res += "\nSuggestion: " + correct_input;
27  }
28  return res;
29 }
30 
33  std::string reason,
34  std::string option,
35  std::string correct_input)
36  : cprover_exception_baset(std::move(reason)),
37  option(std::move(option)),
38  correct_input(std::move(correct_input))
39 {
40 }
41 
43  : cprover_exception_baset(std::move(message))
44 {
45 }
46 
48  : cprover_exception_baset(std::move(message))
49 {
50 }
51 
53  std::string message)
54  : cprover_exception_baset(std::move(message)),
55  source_location(source_locationt::nil())
56 {
57 }
58 
60 {
61  std::string ret(reason);
62 
63  if(!source_location.is_nil())
64  ret += " (at: " + source_location.as_string() + ")";
65 
66  if(!diagnostics.empty())
67  ret += "\n" + diagnostics;
68 
69  return ret;
70 }
71 
73  std::string message)
74  : cprover_exception_baset(std::move(message))
75 {
76 }
77 
79  : cprover_exception_baset(std::move(reason))
80 {
81 }
82 
84  : cprover_exception_baset(std::move(reason))
85 {
86 }
87 
89  std::string reason,
90  source_locationt source_location)
91  : invalid_input_exceptiont(std::move(reason)),
92  source_location(std::move(source_location))
93 {
94 }
95 
97 {
98  return source_location.as_string() + ": " + reason;
99 }
analysis_exceptiont(std::string reason)
Base class for exceptions thrown in the cprover project.
Definition: c_errors.h:64
virtual std::string what() const
A human readable description of what went wrong.
std::string reason
The reason this exception was generated.
Definition: c_errors.h:83
deserialization_exceptiont(std::string message)
incorrect_goto_program_exceptiont(std::string message)
std::string what() const override
A human readable description of what went wrong.
invalid_command_line_argument_exceptiont(std::string reason, std::string option, std::string correct_input="")
std::string what() const override
A human readable description of what went wrong.
std::string correct_input
In case we have samples of correct input to the option.
std::string option
The full command line option (not the argument) that got erroneous input.
Thrown when user-provided input cannot be processed.
invalid_input_exceptiont(std::string reason)
std::string what() const override
A human readable description of what went wrong.
invalid_source_file_exceptiont(std::string reason, source_locationt source_location)
bool is_nil() const
Definition: irep.h:368
std::string as_string() const
system_exceptiont(std::string message)
unsupported_operation_exceptiont(std::string message)
message is the unsupported operation causing this fault to occur.