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

name() method from fcf::Exception class

const char* name() 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 unique string identifier of the exception type.

The name method returns the short, unique string identifier associated with the specific exception type.

This identifier is typically used for logging, telemetry, or programmatic error categorization without needing to parse the full, human-readable message. It corresponds to the string provided during the exception's creation (e.g., via the message or the constructor parameters).

For example, if an exception is declared with the identifier "FCF_LOGIC", the name method will return exactly that string.

Result
const char*
- A pointer to a null-terminated string containing the exception's short name.

Example: Retrieving the exception identifier

Demonstrating how to catch a specific exception and use the name method to retrieve its programmatic identifier.

#include <iostream> #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> int main() { try { // 1. Throw a specific exception defined via macros // The identifier for LogicException is "FCF_LOGIC" throw fcf::LogicException(__FILE__, __LINE__, "Test message"); } catch (const fcf::Exception& e) { // 2. Use the name method // to retrieve the short identifier for error categorization std::cout << "Exception Type ID: " << e.name() << std::endl; // 3. Also print the full formatted message for comparison std::cout << "Full Message: " << e.what() << std::endl; } return 0; }

Output:

Exception Type ID: FCF_LOGIC Full Message: Logic error: Test message Position: /home/user/application/main.cpp:9

The name method provides a clean way to identify the error category without the overhead of full message formatting.