Class: fcf::Error
Package: fcfBasis
File:
bits/PartException/ErrorDecl.hpp
(
link_to_the_declaration_in_the_file
)
Implementation file:
bits/PartException/Error.ipp
(
link_to_the_implementation_in_the_file
)
Available from version: 1.0.1
Resets the error state to a clean, default condition.
The clear method is used to return an fcf::Error object to its initial state, representing a successful operation with no error information.
When called, the method performs the following operations:
- Error Name Reset: The error member is set to
0 (null), clearing any associated error identifier.
- Exception Reset: If the exception pointer is not null, the fcf::Exception object it points to is reset to its default-constructed state.
Example: Resetting an error state
Demonstrating how to use the clear method to reset an error object after an error has been recorded.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
#include <iostream>
int main() {
// 1. Initialize an error object and trigger an error state
fcf::Error err;
// We raise a LogicException to populate the error state
err.raise<fcf::LogicException>(__FILE__, __LINE__, "Critical failure detected");
// 2. Verify that the error object is currently active
if (err) {
std::cout << "Error detected: " << err.error << std::endl;
}
// 3. Use clear() to reset the error object to a clean state
err.clear();
// 4. Verify that the error object is now clean (successful state)
if (!err) {
std::cout << "Error has been cleared successfully." << std::endl;
} else {
std::cout << "Error is still active!" << std::endl;
}
return 0;
}
Output:
Error detected: FCF_LOGIC
Error has been cleared successfully.
The clear method is essential for reusing error objects in loops or long-running processes without carrying over previous error states.