Type: const char*
Class: fcf::Error
Package: fcfBasis
File:
bits/PartException/ErrorDecl.hpp
( link_to_the_declaration_in_the_file )
Available from version: 1.0.1
A pointer to a string containing the registered name of the error, if an error has been recorded.
The error property is a pointer to a constant character string that holds the unique identifier (registered name) of the error currently stored in the fcf::Error structure.
When an error is recorded using the raise method, this pointer is updated to point to the string returned by the exception's name method.
- If the error pointer is
nullptr (or 0), it indicates that no error is currently present in the structure. This state can be checked using the bool operator or the ! operator.
- If it is non-null, it provides a quick way to access the error's name without needing to inspect the full fcf::Exception object.
Example: Accessing Error Name Directly
Demonstrating how the error property is automatically populated when an error is raised and how it can be used to retrieve the error's identifier.
#define FCF_BASIS_IMPLEMENTATION
#include <iostream>
#include <fcfBasis/basis.hpp>
// Define a custom exception for demonstration
FCF_EXCEPTION_DECLARE(MyException, "MY_ERR", "An error occurred: ${{1}}$", 1);
int main() {
fcf::Error err;
// 1. Initially, there is no error
if (!err) {
std::cout << "No error detected initially." << std::endl;
}
// 2. Raise an error
// This call will populate the err.error pointer with "MY_ERR"
err.raise<MyException>(__FILE__, __LINE__, "Something went wrong");
if (err) {
std::cout << "Error detected!" << std::endl;
// Accessing the error property directly
std::cout << "Error name: " << err.error << std::endl;
}
// 3. Clear the error state
err.clear();
if (!err) {
std::cout << "Error has been cleared." << std::endl;
}
return 0;
}
Output:
No error detected initially.
Error detected!
Error name: MY_ERR
Error has been cleared.