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

Error() method from fcf::Error class

[CONSTRUCTOR] Error()
[CONSTRUCTOR] Error(bool a_loud)
[CONSTRUCTOR] Error(fcf::Exception* a_exception)
[CONSTRUCTOR] Error(bool a_loud, fcf::Exception* a_exception)

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

Initializes a new fcf::Error object. It can represent a clean state, a loud error state, or an error associated with a specific fcf::Exception object.

The Error structure is used to carry error information throughout the framework. Its constructors allow you to define the nature of the error:

  • Default State: Creates an error object with loud set to false and no error information. This is used to represent a successful operation.
  • Loudness Control: You can specify if the error is "loud" via the a_loud parameter. A loud error is intended to be thrown as an exception when the error state is checked.
  • Exception Integration: If an fcf::Exception pointer, an error object, is specified, then when the fcf::Error::raise method is called, the exception data will be automatically written to the passed buffer
  • Combined Configuration: Allows simultaneous setting of the loudness flag and the associated exception.

Arguments

bool a_loud = false
- Specifies whether the error should be considered "loud" (should trigger an exception).

fcf::Exception* a_exception = nullptr
- A pointer to an existing fcf::Exception object to associate with this error.

Example: Demonstrating Error initialization modes

An example showing how to create different types of fcf::Error objects: a clean error, an error derived from an exception, and a loud error.

#define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> #include <iostream> int main() { // 1. Default constructor (clean state) // This error object represents a successful operation (no error information). fcf::Error err1; if (!err1) { std::cout << "err1 is clean (no error detected)" << std::endl; } // 2. Triggering an error, followed by writing the exception to the provided buffer fcf::Exception ex; fcf::Error err2(&ex); err2.raise<fcf::LogicException>(__FILE__, __LINE__, "Fail info"); if (err2) { std::cout << "\nerr2 detected error: " << err2.error << std::endl; std::cout << "err2 exception:\n" << err2.exception->what() << std::endl; } return 0; }

Output:

err1 is clean (no error detected) err2 detected error: FCF_LOGIC err2 exception: Logic error: Fail info Position: /home/user/application/main.cpp:16

The fcf::Error constructors provide a flexible way to manage error states, allowing for seamless integration with the exception system.