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

position() method from fcf::Exception class

std::string position() 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 a string representing the source code location where the exception occurred.

The position method retrieves the exact source code location where the exception was instantiated.

The returned string follows the standard filename:line format. This is extremely useful for automated error reporting and debugging, allowing developers to jump directly to the problematic line of code.

  • Format: A string consisting of the file path followed by a colon and the line number (e.g., "main.cpp:15").
  • Empty Result: If the exception object was not initialized with file and line information, the method returns an empty string.

Result
std::string
- A string containing the file path and line number.

Example: Retrieving exception position

Catching an exception and using the position method to print the exact source location.

#include <iostream> #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> int main() { try { // 1. Throw an exception with context // This uses the template constructor to include file and line throw fcf::LogicException(__FILE__, __LINE__, "Critical failure"); } catch (const fcf::Exception& e) { // 2. Retrieve the position // e.position() will return something like "main.cpp:10" std::cout << "Exception Location: " << e.position() << std::endl; } return 0; }

Output:

Exception Location: /home/user/application/main.cpp:9

The position method provides a direct way to access the source code coordinates of an error.