Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::exception Class Reference

Used to generate a useful error report when an exception is thrown. More...

#include <exception.hpp>

Inheritance diagram for fc::exception:
Collaboration diagram for fc::exception:

Public Types

enum  code_enum { code_value = unspecified_exception_code }
 

Public Member Functions

 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_messagesget_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< exceptiondynamic_copy_exception () const
 
exceptionoperator= (const exception &copy)
 
exceptionoperator= (exception &&copy)
 

Static Public Attributes

static constexpr fc::microseconds format_time_limit = fc::milliseconds( 10 )
 

Protected Attributes

std::unique_ptr< detail::exception_impl > my
 

Friends

void to_variant (const exception &e, variant &v)
 
void from_variant (const variant &e, exception &ll)
 

Detailed Description

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.

Member Enumeration Documentation

◆ code_enum

Enumerator
code_value 

Definition at line 62 of file exception.hpp.

63 {
65 };
@ unspecified_exception_code
Definition exception.hpp:20

Constructor & Destructor Documentation

◆ exception() [1/6]

fc::exception::exception ( int64_t code = unspecified_exception_code,
const std::string & name_value = "exception",
const std::string & what_value = "unspecified" )

Definition at line 93 of file exception.cpp.

96 :my( new detail::exception_impl() )
97 {
98 my->_code = code;
99 my->_what = what_value;
100 my->_name = name_value;
101 }
int64_t code() const
std::unique_ptr< detail::exception_impl > my
Here is the call graph for this function:

◆ exception() [2/6]

fc::exception::exception ( log_message && msg,
int64_t code = unspecified_exception_code,
const std::string & name_value = "exception",
const std::string & what_value = "unspecified" )

Definition at line 103 of file exception.cpp.

107 :my( new detail::exception_impl() )
108 {
109 my->_code = code;
110 my->_what = what_value;
111 my->_name = name_value;
112 my->_elog.push_back( fc::move( msg ) );
113 }
Here is the call graph for this function:

◆ exception() [3/6]

fc::exception::exception ( log_messages && msgs,
int64_t code = unspecified_exception_code,
const std::string & name_value = "exception",
const std::string & what_value = "unspecified" )

Definition at line 41 of file exception.cpp.

44 :my( new detail::exception_impl() )
45 {
46 my->_code = code;
47 my->_what = what_value;
48 my->_name = name_value;
49 my->_elog = fc::move(msgs);
50 }
Here is the call graph for this function:

◆ exception() [4/6]

fc::exception::exception ( const log_messages & msgs,
int64_t code = unspecified_exception_code,
const std::string & name_value = "exception",
const std::string & what_value = "unspecified" )

Definition at line 52 of file exception.cpp.

57 :my( new detail::exception_impl() )
58 {
59 my->_code = code;
60 my->_what = what_value;
61 my->_name = name_value;
62 my->_elog = msgs;
63 }
Here is the call graph for this function:

◆ 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]

fc::exception::exception ( exception && e)

Definition at line 117 of file exception.cpp.

118 :my( fc::move(c.my) ){}

◆ ~exception()

fc::exception::~exception ( )
virtual

Definition at line 124 of file exception.cpp.

124{}

Member Function Documentation

◆ append_log()

void fc::exception::append_log ( log_message m)

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 ( )

Definition at line 122 of file exception.cpp.

122{ return my->_code; }
Here is the caller graph for this function:

◆ dynamic_copy_exception()

exception_ptr fc::exception::dynamic_copy_exception ( ) const
virtual

This is equivalent to:

try { throwAsDynamic_exception(); }
catch( ... ) { return std::current_exception(); }

Reimplemented in fc::std_exception_wrapper, and fc::unhandled_exception.

Definition at line 264 of file exception.cpp.

265 {
266 return std::make_shared<exception>(*this);
267 }
Here is the caller graph for this function:

◆ 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()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_log()

const log_messages & fc::exception::get_log ( ) const
Returns
a reference to log messages that have been added to this log.

Definition at line 147 of file exception.cpp.

147{ return my->_elog; }
Here is the caller graph for this function:

◆ name()

const char * fc::exception::name ( ) const
throw ( )

Definition at line 120 of file exception.cpp.

120{ return my->_name.c_str(); }
Here is the caller graph for this function:

◆ operator=() [1/2]

exception & fc::exception::operator= ( const exception & copy)

Definition at line 293 of file exception.cpp.

294 {
295 *my = *copy.my;
296 return *this;
297 }
void copy(const path &from, const path &to)
Here is the call graph for this function:

◆ operator=() [2/2]

exception & fc::exception::operator= ( exception && copy)

Definition at line 299 of file exception.cpp.

300 {
301 my = std::move(copy.my);
302 return *this;
303 }
Here is the call graph for this function:

◆ to_detail_string()

string fc::exception::to_detail_string ( log_level ll = log_level::all) const

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 {
160 const auto deadline = fc::time_point::now() + format_time_limit;
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"; //fc::format_string( itr->get_format(), itr->get_data() ) <<"\n";
174 ss << " " << json::to_string( itr->get_data(), deadline ) << "\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 }
190 return ss.str();
191 }
static constexpr fc::microseconds format_time_limit
Definition exception.hpp:60
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
Definition json.cpp:674
static time_point now()
Definition time.cpp:14
static const Segment ss(Segment::ss)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_string()

string fc::exception::to_string ( log_level ll = log_level::info) const

Generates a user-friendly error report.

Definition at line 196 of file exception.cpp.

197 {
198 const auto deadline = fc::time_point::now() + format_time_limit;
199 std::stringstream ss;
200 try {
201 ss << my->_what;
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 {
211 FC_CHECK_DEADLINE(deadline);
212 ss << fc::format_string( itr->get_format(), itr->get_data(), true) << "\n";
213 // ss << " " << itr->get_context().to_string() <<"\n";
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 }
223 return ss.str();
224 } catch( std::bad_alloc& ) {
225 throw;
226 } catch( ... ) {
227 ss << "<- exception in to_string.\n";
228 }
229 return ss.str();
230 }
#define FC_CHECK_DEADLINE(DEADLINE,...)
fc::string format_string(const fc::string &, const variant_object &, bool minimize=false)
Definition variant.cpp:773
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 {
239 auto s = fc::format_string( itr->get_format(), itr->get_data() );
240 if (!s.empty()) {
241 return s;
242 }
243 }
244 return string();
245 }
std::string string
Definition string.hpp:10
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ what()

const char * fc::exception::what ( ) const
overridenoexcept

Definition at line 121 of file exception.cpp.

121{ return my->_what.c_str(); }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ from_variant

void from_variant ( const variant & e,
exception & ll )
friend

Definition at line 134 of file exception.cpp.

135 {
136 auto obj = v.get_object();
137 if( obj.contains( "stack" ) )
138 ll.my->_elog = obj["stack"].as<log_messages>();
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

void to_variant ( const exception & e,
variant & v )
friend

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 }

Member Data Documentation

◆ format_time_limit

fc::microseconds fc::exception::format_time_limit = fc::milliseconds( 10 )
staticconstexpr

Definition at line 60 of file exception.hpp.

◆ my

std::unique_ptr<detail::exception_impl> fc::exception::my
protected

Definition at line 134 of file exception.hpp.


The documentation for this class was generated from the following files: