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

loud from class fcf::Error

Property: loud = false

Type: bool

Class: fcf::Error

Package: fcfBasis

File: bits/PartException/ErrorDecl.hpp ( link_to_the_declaration_in_the_file )

Available from version: 1.0.1

Determines whether the raise method should throw an exception or simply record the error state.

The loud property is a boolean flag that controls the behavior of the raise method within the fcf::Error structure.

  • If false (default): The raise method will only populate the error string and the exception pointer. The program execution continues normally. This is useful in scenarios requiring rapid error handling, where throwing an exception would be an overly costly operation.
  • If true: The raise method will record the error AND perform a standard C++ throw of the specified exception. This is used for critical errors that must interrupt the current control flow and be handled by a try-catch block.

Example: Switching between error recording and exception throwing

Demonstrating how the fcf::Error::loud property changes the behavior of the raise method.

#define FCF_BASIS_IMPLEMENTATION #include <iostream> #include <fcfBasis/basis.hpp> // Define a custom exception for demonstration FCF_EXCEPTION_DECLARE(DemoException, "DEMO_ERR", "Something went wrong: ${{1}}$", 1); int main() { // 1. Soft error mode (loud = false) fcf::Error softError; // By default, loud is false. We explicitly set it for clarity. softError.loud = false; // This call will NOT throw an exception. It only records the error. softError.raise<DemoException>(__FILE__, __LINE__, "Quiet error"); if (softError) { std::cout << "Quiet error recorded: " << softError.error << std::endl; } // 2. Hard error mode (loud = true) fcf::Error hardError; // Setting loud to true makes the raise method behave like a throw statement. hardError.loud = true; try { std::cout << "\nAttempting to raise a loud error..." << std::endl; // This call WILL throw a DemoException. hardError.raise<DemoException>(__FILE__, __LINE__, "Hard error"); } catch (const fcf::Exception& e) { std::cout << "Caught exception: " << e.what() << std::endl; } return 0; }

Output:

Quiet error recorded: DEMO_ERR Attempting to raise a loud error... Caught exception: Something went wrong: Hard error Position: /home/user/application/main.cpp:29