FC++  v0.9.0-9e9b65
FileCatalyst Fast File Transfers - C++ Library
fc::Exception Class Reference

fc::Exception objects represent a C++ exception and usually includes stack traces and optional parameters to describe the internal state of FC++ at the time the exception happened. More...

#include <FCException.hpp>

Inheritance diagram for fc::Exception:
Collaboration diagram for fc::Exception:

Public Member Functions

virtual ~Exception () FC_NOEXCEPT
 Destructor. More...
 
 Exception (FC_WHERE_DEF, const boost::system::error_code &ec, const std::string &description, const fc::StrMap &m=fc::emptyMap())
 Constructor with a boost::system::error_code value. More...
 
 Exception (FC_WHERE_DEF, const std::string &description, const fc::StrMap &m=fc::emptyMap())
 Constructor with a simple text message. More...
 
 Exception (FC_WHERE_DEF, const fc::FtpServerReplyCodes code, const std::string &reply, const std::string &description, const fc::StrMap &m=fc::emptyMap())
 Constructor with a FTP server reply. These objects are usually constructed when the FTP server response is unexpected. More...
 
virtual const char * what () const FC_NOEXCEPT
 Inherited from std::exception to provide a very simple 1-line text string. More...
 
virtual operator std::string () const
 Convert the exception to a very detailed multi-line text block. More...
 
virtual std::string to_string () const
 Convert the exception to a very detailed multi-line text block. More...
 
virtual void display (const bool showDisplayStack=true) const
 Display the exception using std::cout. Calls to_string() to format the message. More...
 

Static Public Member Functions

static std::string getLogFilename ()
 Get the name of the file used to record FC++ exceptions. More...
 
static bool createLogFile (const bool truncateNow=false)
 Create the fc_exception.log file used to record exceptions in FC++. More...
 
static bool truncateLogFile ()
 Alias for fc::Exception::createLogFile() to re-create the log file in which FC++ exceptions are logged. More...
 
static bool removeLogFile ()
 Remove the fc_exception.log file. More...
 

Public Attributes

int othererror
 on Windows, this is set to WSAGetLastError() More...
 
int olderrno
 errno at the time the exception was created More...
 
int oldherrno
 of limited use; not typically shown More...
 
fc::FtpServerReplyCodes ftpReplyCode
 FTP server reply code. More...
 
std::string ftpReplyText
 FTP server raw text reply. More...
 
int lineNumber
 source file line number More...
 
std::string filename
 source file More...
 
std::string function
 source function More...
 
std::string text
 1-line exception text More...
 
std::chrono::high_resolution_clock::time_point timestamp
 time when the exception was created More...
 
fc::StrVec callstack
 call stack where the exception was created More...
 
fc::StrMap map
 additional/optional debug information More...
 
boost::system::error_code errorCode
 typically set by boost::asio More...
 

Protected Member Functions

virtual Exceptioninit (FC_WHERE_DEF, const fc::FtpServerReplyCodes code, const std::string &reply, const std::string &description, const fc::StrMap &map)
 Initialize the exception, including getting the call stack where the exception was generated. More...
 

Detailed Description

fc::Exception objects represent a C++ exception and usually includes stack traces and optional parameters to describe the internal state of FC++ at the time the exception happened.

These exceptions can be thrown from anywhere in the fc::... namespace.

Constructor & Destructor Documentation

◆ ~Exception()

fc::Exception::~Exception ( )
virtual

Destructor.

◆ Exception() [1/3]

fc::Exception::Exception ( FC_WHERE_DEF  ,
const boost::system::error_code &  ec,
const std::string &  description,
const fc::StrMap m = fc::emptyMap() 
)

Constructor with a boost::system::error_code value.

These objects are usually constructed due to a Boost API returning an error, such as boost::asio.

References FC_WHERE_PASS, init(), and fc::kInvalid.

Here is the call graph for this function:

◆ Exception() [2/3]

fc::Exception::Exception ( FC_WHERE_DEF  ,
const std::string &  description,
const fc::StrMap m = fc::emptyMap() 
)

Constructor with a simple text message.

References FC_WHERE_PASS, init(), and fc::kInvalid.

Here is the call graph for this function:

◆ Exception() [3/3]

fc::Exception::Exception ( FC_WHERE_DEF  ,
const fc::FtpServerReplyCodes  code,
const std::string &  reply,
const std::string &  description,
const fc::StrMap m = fc::emptyMap() 
)

Constructor with a FTP server reply. These objects are usually constructed when the FTP server response is unexpected.

References FC_WHERE_PASS, and init().

Here is the call graph for this function:

Member Function Documentation

◆ what()

virtual const char* fc::Exception::what ( ) const
inlinevirtual

Inherited from std::exception to provide a very simple 1-line text string.

Example output:

Network error.

To get a more detailed multi-line error message, call to_string().

References text.

◆ operator std::string()

fc::Exception::operator std::string ( ) const
virtual

Convert the exception to a very detailed multi-line text block.

catch( const fc::Exception &e )
{
std::cout << std::string(e) << std::endl;
}

This is the same as calling to_string().

Example output:

Exception or error detected: Network error.
2014-10-10 03:25:07.240150
Pid 27375: src/testapp
Tid 27394
Errno 111: Connection refused
socketWriteUdpChannel(): FCClientUdpChannelSocket.cpp, line #158
Call stack where the exception was created:
1: fc::Client::socketWriteUdpChannel(fc::Buffer&, fc::TransferStats&)
2: fc::Client::udpUploadWriteThread(fc::TransferStats&, fc::UdpTransfer&)
3: /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0xb1bf0) [0x7fc0e8b3fbf0]
4: /lib/x86_64-linux-gnu/libpthread.so.0(+0x8182) [0x7fc0e93d2182]
5: clone()
Additional information:
1: Bandwidth: 5.00 Mbps
2: Bandwidth Slow Start: 5.00 Mbps
3: Block size: 4194304
4: Buffer size: 16.00 KiB
...
94: Version (base): 3.4
95: Version (library): 0.6.6-802
See also
to_string()
what()

References fc::formatTimestamp2().

Here is the call graph for this function:

◆ to_string()

virtual std::string fc::Exception::to_string ( ) const
inlinevirtual

Convert the exception to a very detailed multi-line text block.

Alias for operator std::string().

catch( const fc::Exception &e )
{
std::cout
<< "Exception caught:" << std::endl
<< e.to_string() << std::endl;
}
See also
what()

◆ display()

void fc::Exception::display ( const bool  showDisplayStack = true) const
virtual

Display the exception using std::cout. Calls to_string() to format the message.

Parameters
[in]showDisplayStackThe call stack where the exception was created is always shown, but the call stack where fc::Exception::display() is being called from will only be shown if showDisplayStack is set to true.
Here is the caller graph for this function:

◆ getLogFilename()

std::string fc::Exception::getLogFilename ( )
static

Get the name of the file used to record FC++ exceptions.

This can change depending on fc::Options::setLogFileOutputDir(). If this file doesn't exist, then exceptions thrown by FC++ are not recorded. If this file exists, then any exception created by the FC++ library will be appended to this text file.

See also
fc::Exception::createLogFile()
fc::Exception::removeLogFile()
fc::Logging::get_filename()

References FC_EXCEPTION_FILENAME, fc::Name::full(), fc::Options::getLogFileOutputDir(), and fc::Name::isRelative().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createLogFile()

bool fc::Exception::createLogFile ( const bool  truncateNow = false)
static

Create the fc_exception.log file used to record exceptions in FC++.

If this file exists, then any exception created by the FC++ library will be recorded in this file. The fc_exception.log file can be manually created, but on some embedded systems (such as phones) it can be difficult to determine the exact path that will be used to run an application. The method createLogFile() was created specifically for those instances when it is difficult or impossible to determine beforehand the directory structure.

Parameters
[in]truncateNowBy default, the FC_EXCEPTION_FILENAME log file is appended when an exception is logged. This can cause the file to grow over time. If truncateNow is set to true, then the existing FC_EXCEPTION_FILENAME log file will be immediately truncated. All previous exceptions will be removed.
Returns
TRUE if the fc_exception.log file is OK.
FALSE if the fc_exception.log file cannot be created. E.g., read-only filesystem, or permission issues.
See also
FC_EXCEPTION_FILENAME
fc::Exception::getLogFilename()
fc::Options::setLogFileOutputDir()
fc::Logging::enable()
fc::Logging::EType::kException

References fc::SummaryLog::getLogFilename(), fc::libfcBitSize(), and fc::libfcVersionStr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ truncateLogFile()

static bool fc::Exception::truncateLogFile ( )
inlinestatic

Alias for fc::Exception::createLogFile() to re-create the log file in which FC++ exceptions are logged.

See also
fc::Logging::enable()
fc::Logging::EType::kException

References createLogFile().

Here is the call graph for this function:

◆ removeLogFile()

bool fc::Exception::removeLogFile ( )
static

Remove the fc_exception.log file.

Returns
TRUE if the file was removed, or if it didn't exist.
FALSE if the file cannot be removed. E.g., read-only filesystem, or permission issues.
See also
fc::Exception::createLogFile()
fc::Exception::getLogFilename()
fc::Options::setLogFileOutputDir()
fc::Logging::disable()
fc::Logging::EType::kException

References fc::SummaryLog::getLogFilename().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

fc::Exception & fc::Exception::init ( FC_WHERE_DEF  ,
const fc::FtpServerReplyCodes  code,
const std::string &  reply,
const std::string &  description,
const fc::StrMap map 
)
protectedvirtual

Initialize the exception, including getting the call stack where the exception was generated.

This protected method is automatically called from the fc::Exception constructors.

Note
If you create an empty file named fc_exception.log in the application's current working directory or the directory specified in fc::Options::setLogFileOutputDir(), the FC++ library will append information on any C++ exceptions thrown.
See also
FC_EXCEPTION_FILENAME
fc::Exception::createLogFile()

References fc::SummaryLog::add(), and fc::SummaryLog::getLogFilename().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ othererror

int fc::Exception::othererror

on Windows, this is set to WSAGetLastError()

◆ olderrno

int fc::Exception::olderrno

errno at the time the exception was created

◆ oldherrno

int fc::Exception::oldherrno

of limited use; not typically shown

◆ ftpReplyCode

fc::FtpServerReplyCodes fc::Exception::ftpReplyCode

FTP server reply code.

◆ ftpReplyText

std::string fc::Exception::ftpReplyText

FTP server raw text reply.

◆ lineNumber

int fc::Exception::lineNumber

source file line number

◆ filename

std::string fc::Exception::filename

source file

◆ function

std::string fc::Exception::function

source function

◆ text

std::string fc::Exception::text

1-line exception text

See also
what()

◆ timestamp

std::chrono::high_resolution_clock::time_point fc::Exception::timestamp

time when the exception was created

◆ callstack

fc::StrVec fc::Exception::callstack

call stack where the exception was created

See also
fc::getBacktrace()

◆ map

fc::StrMap fc::Exception::map

additional/optional debug information

◆ errorCode

boost::system::error_code fc::Exception::errorCode

typically set by boost::asio


The documentation for this class was generated from the following files:
fc::Exception
fc::Exception objects represent a C++ exception and usually includes stack traces and optional parame...
Definition: FCException.hpp:24
fc
Definition: FCControl.hpp:17
fc::Mbps
uint64_t Mbps(const int rate)
Convert easy-to-use numerical values to bps values.
Definition: FCOptions.hpp:271
so
FileCatalyst C API Written by Stéphane stephanecharette gmail info filecatalyst com Contact Unlimi Tech Software Inc for FileCatalyst and FC license details OpenSSL with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution Boost free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do so
Definition: 03_licence.txt:32
fc::Exception::Exception
Exception(FC_WHERE_DEF, const boost::system::error_code &ec, const std::string &description, const fc::StrMap &m=fc::emptyMap())
Constructor with a boost::system::error_code value.
Definition: FCException.cpp:18
fc::Exception::to_string
virtual std::string to_string() const
Convert the exception to a very detailed multi-line text block.
Definition: FCException.hpp:99