FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

file() method from fcf::Exception class

const char* file() const

Class: fcf::Exception

Package: fcfBasis

File: bits/PartException/ExceptionDecl.hpp ( link_to_the_declaration_in_the_file )

Implementation file: bits/PartException/Exception.hpp ( link_to_the_implementation_in_the_file )

Available from version: 1.0.1

Returns the name of the file where the exception occurred.

The file method provides access to the source file path where the fcf::Exception was instantiated.

This method is a direct accessor for the internal metadata stored within the exception object. It is particularly useful for low-level error reporting systems or custom loggers that need to categorize errors by their origin in the source tree.

Result
const char*
- A pointer to a null-terminated string containing the file path.

Example: Accessing file information

Demonstrating how to catch an exception and retrieve the file path where it originated using the file method.

#include <iostream> #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> int main() { try { // 1. Throw an exception and provide file and line information // Using the template constructor throw fcf::LogicException(__FILE__, __LINE__, "An unexpected error occurred"); } catch (const fcf::Exception& e) { // 2. Retrieve the file path using the file() method std::cout << "Error source file: " << e.file() << std::endl; } return 0; }

Output:

Error source file: main.cpp

The file method allows for precise identification of the error's origin in the source code.