java.lang.Object
io.qt.core.QScopeGuard
- All Implemented Interfaces:
AutoCloseable
QScopeGuard is a class of which the sole purpose is to run the function f
at the end of a try-with-resource block.
This is useful for guaranteeing your cleanup code is executed, whether the function is exited normally,
exited early by a return statement, or exited by an exception.
See QScopeGuard.
Example:
QIODevice device = ...
try(var guard = new QScopeGuard(device::close)){
if(!device.open())
guard.dismiss();
else
device.write(...);
}
-
Constructor Summary
ConstructorDescriptionQScopeGuard
(Runnable runnable) Create a scope guard that will executefunction
at the end of the scope. -
Method Summary
-
Constructor Details
-
QScopeGuard
Create a scope guard that will executefunction
at the end of the scope.- Parameters:
function
- runnable to be executed
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
-
dismiss
Disarms the scope guard, so that the function F will not be called at the end of the scope.
-