loud from class fcf::Error
Type:
Class:
Package: fcfBasis
File: bits/PartException/ErrorDecl.hpp ( link_to_the_declaration_in_the_file )
Available from version: 1.0.1
Determines whether the
The
- If
false (default): Theraise method will only populate theerror string and theexception 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 : Theraise method will record the error AND perform a standard C++throwof the specified exception. This is used for critical errors that must interrupt the current control flow and be handled by atry-catchblock.
Example: Switching between error recording and exception throwing
Demonstrating how the
#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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.