mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
@@ -15798,7 +15798,7 @@ This can be messy:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Simulating RAII can be non-trivial, especially in functions with multiple resources and multiple possible errors.
|
Simulating RAII can be non-trivial, especially in functions with multiple resources and multiple possible errors.
|
||||||
A not uncommon technique is to gather cleanup at the end of the function to avoid repetition:
|
A not uncommon technique is to gather cleanup at the end of the function to avoid repetition (note the extra scope around `g2` is undesirable but necessary to make the `goto` version compile):
|
||||||
|
|
||||||
std::pair<int, error_indicator> user()
|
std::pair<int, error_indicator> user()
|
||||||
{
|
{
|
||||||
@@ -15810,6 +15810,7 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
Gadget g2 = make_gadget(17);
|
Gadget g2 = make_gadget(17);
|
||||||
if (!g2.valid()) {
|
if (!g2.valid()) {
|
||||||
err = g2_error;
|
err = g2_error;
|
||||||
@@ -15821,6 +15822,7 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (g1.valid()) cleanup(g1);
|
if (g1.valid()) cleanup(g1);
|
||||||
|
|||||||
Reference in New Issue
Block a user