本文整理汇总了C++中Exception::error_code方法的典型用法代码示例。如果您正苦于以下问题:C++ Exception::error_code方法的具体用法?C++ Exception::error_code怎么用?C++ Exception::error_code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::error_code方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: error_logger
//////////////////////////////
/// ERROR LOGGER
//////////////////////////////
void error_logger(const Exception & e) {
// Open the log file.
File error_log("errorlog.txt");
// Message for dual-output.
string message = "Exception " + int_to_str(e.error_code()) + ": " +
e.error_message();
// Insert a new line at the end with the error code and message.
error_log.insert_line(error_log.num_lines(), message);
// Close and save the file.
error_log.close(true);
// Output to standard out, too.
cout << message << endl;
}
示例2: log_file
//////////////////////////////////////////////////////////////////////
/// @fn ErrorLog(Exception e, string filename)
/// @brief -- Takes an Exception and reports the error to a log file
/// as denoted by filename.
//////////////////////////////////////////////////////////////////////
ErrorLog::ErrorLog(Exception e, string filename) {
// Open a log file (creates it if one doesn't exist).
File log_file(filename);
// Get the time from the system.
time_t curr_time;
time(&curr_time);
// Char array for ctime_s (function guarantees a return size of 26)
char time_char[26];
// Retrieve.
ctime_s(time_char, sizeof(time_char), &curr_time);
// A string for us to store it in.
string time_str = time_char;
// ctime() includes a '\n' character at the end, and
// we don't want that.
time_str = "[" + str_left(time_str, time_str.length() - 1) + "]";
// Insert the date/time the error was found.
string error_line = time_str;
// Add the error code.
error_line += " Error " + int_to_str(e.error_code());
// And the error message.
error_line += ": " + e.error_message();
// Put it at the end of the file.
log_file.insert_line(log_file.num_lines(), error_line);
log_file.save_file();
log_file.close();
}