Used to generate a useful error report when an exception is thrown.
More...
#include <exception.hpp>
|
| exception (int64_t code=unspecified_exception_code, const std::string &name_value="exception", const std::string &what_value="unspecified") |
|
| exception (log_message &&, int64_t code=unspecified_exception_code, const std::string &name_value="exception", const std::string &what_value="unspecified") |
|
| exception (log_messages &&, int64_t code=unspecified_exception_code, const std::string &name_value="exception", const std::string &what_value="unspecified") |
|
| exception (const log_messages &, int64_t code=unspecified_exception_code, const std::string &name_value="exception", const std::string &what_value="unspecified") |
|
| exception (const exception &e) |
|
| exception (exception &&e) |
|
virtual | ~exception () |
|
const char * | name () const throw () |
|
int64_t | code () const throw () |
|
const char * | what () const noexcept override |
|
const log_messages & | get_log () const |
|
void | append_log (log_message m) |
|
std::string | to_detail_string (log_level ll=log_level::all) const |
|
std::string | to_string (log_level ll=log_level::info) const |
|
std::string | top_message () const |
|
virtual NO_RETURN void | dynamic_rethrow_exception () const |
|
virtual std::shared_ptr< exception > | dynamic_copy_exception () const |
|
exception & | operator= (const exception ©) |
|
exception & | operator= (exception &©) |
|
|
std::unique_ptr< detail::exception_impl > | my |
|
At each level in the stack where the exception is caught and rethrown a new log_message is added to the exception.
exception's are designed to be serialized to a variant and deserialized from an variant.
- See also
- FC_THROW_EXCEPTION
-
FC_RETHROW_EXCEPTION
-
FC_RETHROW_EXCEPTIONS
Definition at line 57 of file exception.hpp.
◆ code_enum
Definition at line 62 of file exception.hpp.
63 {
65 };
@ unspecified_exception_code
◆ exception() [1/6]
Definition at line 93 of file exception.cpp.
96 :
my(
new detail::exception_impl() )
97 {
99 my->_what = what_value;
100 my->_name = name_value;
101 }
std::unique_ptr< detail::exception_impl > my
◆ exception() [2/6]
Definition at line 103 of file exception.cpp.
107 :
my(
new detail::exception_impl() )
108 {
110 my->_what = what_value;
111 my->_name = name_value;
112 my->_elog.push_back( fc::move( msg ) );
113 }
◆ exception() [3/6]
Definition at line 41 of file exception.cpp.
44 :
my(
new detail::exception_impl() )
45 {
47 my->_what = what_value;
48 my->_name = name_value;
49 my->_elog = fc::move(msgs);
50 }
◆ exception() [4/6]
Definition at line 52 of file exception.cpp.
57 :
my(
new detail::exception_impl() )
58 {
60 my->_what = what_value;
61 my->_name = name_value;
63 }
◆ exception() [5/6]
fc::exception::exception |
( |
const exception & | e | ) |
|
Definition at line 114 of file exception.cpp.
115 :
my(
new detail::exception_impl(*c.my) )
116 { }
◆ exception() [6/6]
◆ ~exception()
fc::exception::~exception |
( |
| ) |
|
|
virtual |
◆ append_log()
Definition at line 148 of file exception.cpp.
149 {
150 my->_elog.emplace_back( fc::move(m) );
151 }
◆ code()
int64_t fc::exception::code |
( |
| ) |
const |
throw | ( | ) | | | |
◆ dynamic_copy_exception()
◆ dynamic_rethrow_exception()
NO_RETURN void fc::exception::dynamic_rethrow_exception |
( |
| ) |
const |
|
virtual |
Throw this exception as its most derived type.
- Note
- does not return.
Rethrows the exception restoring the proper type based upon the error code. This is used to propagate exception types across conversions to/from JSON
Reimplemented in fc::std_exception_wrapper, and fc::unhandled_exception.
Definition at line 259 of file exception.cpp.
260 {
262 }
void NO_RETURN rethrow(const exception &e) const
static exception_factory & instance()
◆ get_log()
- Returns
- a reference to log messages that have been added to this log.
Definition at line 147 of file exception.cpp.
◆ name()
const char * fc::exception::name |
( |
| ) |
const |
throw | ( | ) | | | |
◆ operator=() [1/2]
Definition at line 293 of file exception.cpp.
294 {
296 return *this;
297 }
void copy(const path &from, const path &to)
◆ operator=() [2/2]
◆ to_detail_string()
Generates a detailed string including file, line, method, and other information that is generally only useful for developers.
Definition at line 158 of file exception.cpp.
159 {
161 std::stringstream
ss;
162 try {
163 try {
164 ss << variant(
my->_code ).as_string();
165 } catch( std::bad_alloc& ) {
166 throw;
167 } catch( ... ) {
168 ss <<
"<- exception in to_detail_string.";
169 }
170 ss <<
" " <<
my->_name <<
": " <<
my->_what <<
"\n";
171 for(
auto itr =
my->_elog.begin(); itr !=
my->_elog.end(); ++itr ) {
172 try {
173 ss << itr->get_message() <<
"\n";
175 ss <<
" " << itr->get_context().to_string() <<
"\n";
176 } catch( std::bad_alloc& ) {
177 throw;
178 } catch( const fc::timeout_exception& e) {
179 ss <<
"<- timeout exception in to_detail_string: " << e.what() <<
"\n";
180 break;
181 } catch( ... ) {
182 ss <<
"<- exception in to_detail_string.\n";
183 }
184 }
185 } catch( std::bad_alloc& ) {
186 throw;
187 } catch( ... ) {
188 ss <<
"<- exception in to_detail_string.\n";
189 }
191 }
static constexpr fc::microseconds format_time_limit
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
static const Segment ss(Segment::ss)
◆ to_string()
Generates a user-friendly error report.
Definition at line 196 of file exception.cpp.
197 {
199 std::stringstream
ss;
200 try {
202 try {
203 ss <<
" (" << variant(
my->_code ).as_string() <<
")\n";
204 } catch( std::bad_alloc& ) {
205 throw;
206 } catch( ... ) {
207 ss <<
"<- exception in to_string.\n";
208 }
209 for(
auto itr =
my->_elog.begin(); itr !=
my->_elog.end(); ++itr ) {
210 try {
213
214 } catch( std::bad_alloc& ) {
215 throw;
216 } catch( const fc::timeout_exception& e) {
217 ss <<
"<- timeout exception in to_string: " << e.what();
218 break;
219 } catch( ... ) {
220 ss <<
"<- exception in to_string.\n";
221 }
222 }
224 } catch( std::bad_alloc& ) {
225 throw;
226 } catch( ... ) {
227 ss <<
"<- exception in to_string.\n";
228 }
230 }
#define FC_CHECK_DEADLINE(DEADLINE,...)
fc::string format_string(const fc::string &, const variant_object &, bool minimize=false)
◆ top_message()
string fc::exception::top_message |
( |
| ) |
const |
Generates a user-friendly error report.
Definition at line 235 of file exception.cpp.
236 {
237 for(
auto itr =
my->_elog.begin(); itr !=
my->_elog.end(); ++itr )
238 {
242 }
243 }
245 }
◆ what()
const char * fc::exception::what |
( |
| ) |
const |
|
overridenoexcept |
◆ from_variant
Definition at line 134 of file exception.cpp.
135 {
136 auto obj = v.get_object();
137 if( obj.contains( "stack" ) )
139 if( obj.contains( "code" ) )
140 ll.my->_code = obj["code"].as_int64();
141 if( obj.contains( "name" ) )
142 ll.my->_name = obj["name"].as_string();
143 if( obj.contains( "message" ) )
144 ll.my->_what = obj["message"].as_string();
145 }
std::vector< log_message > log_messages
◆ to_variant
Definition at line 126 of file exception.cpp.
127 {
128 v = mutable_variant_object( "code", e.code() )
129 ( "name", e.name() )
130 ( "message", e.what() )
131 ( "stack", e.get_log() );
132
133 }
◆ format_time_limit
◆ my
std::unique_ptr<detail::exception_impl> fc::exception::my |
|
protected |
The documentation for this class was generated from the following files: