xtd 0.2.0
Loading...
Searching...
No Matches
xtd::scope_fail Struct Reference

Definition

Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) technique. It binds resource acquisition and release to initialization and destruction of a variable that holds the resource. There are times when writing a special class for such a variable is not worth the effort. This is when xtd xtd::scope_fail comes into play. xtd::scope_fail is executed only if an exception is in progress.

Namespace
xtd
Library
xtd.core
Remarks
scope_exit_, scope_success_ and scope_fail_ are themselves RAII utilities.
They are designed to make scope-based cleanup and control flow more concise and expressive.
See also scope_fail_ keyword helper.
#include <xtd/xtd>
auto main() -> int {
try {
console::write_line("always (scope_exit)");
};
console::write_line("only on success (scope_success)");
};
console::write_line("only on failure (scope_fail)");
};
// ...
console::write_line("do something...");
// Remove the comment from the following line to test failure
//throw invalid_operation_exception {};
// ...
console::write_line("end normally");
} catch (...) {
console::write_line("caught exception!");
}
}
// This code produces the following output if success :
//
// begin
// do something...
// end normally
// only on success (scope_success)
// always (scope_exit)
// This code produces the following output if throws exception :
//
// begin
// do something...
// only on failure (scope_fail)
// always (scope_exit)
// caught exception!
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
#define scope_exit_
Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) tech...
Definition scope_exit.hpp:128
#define scope_success_
Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) tech...
Definition scope_success.hpp:128
#define scope_fail_
Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) tech...
Definition scope_fail.hpp:128

The documentation for this struct was generated from the following file: