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

line() method from fcf::Exception class

unsigned int line() 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 line number where the exception occurred.

The line method provides access to the specific line number in the source code where the fcf::Exception was instantiated.

This method is part of the metadata provided by the fcf::Exception class, allowing for precise pinpointing of errors during debugging and automated log analysis. When combined with the file method, it offers a complete picture of the error's origin.

Result
unsigned int
- The line number where the exception was thrown.

Example: Retrieving exception line number

Demonstrating how to catch an exception and use the line method to extract the line number.

#include <iostream> #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> int main() { try { // 1. Throw an exception and provide file and line information throw fcf::LogicException(__FILE__, __LINE__, "Something went wrong"); } catch (const fcf::Exception& e) { // 2. Retrieve and print the line number std::cout << "Exception occurred on line: " << e.line() << std::endl; } return 0; }

Output:

Exception occurred on line: 8

The line method is an essential tool for locating the exact point of failure in your source code.