Module qtjambi
Package io.qt.core

Class QScopeGuard

java.lang.Object
io.qt.core.QScopeGuard
All Implemented Interfaces:
AutoCloseable

public final class QScopeGuard extends Object implements 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 Details

    • QScopeGuard

      public QScopeGuard(Runnable runnable)
      Create a scope guard that will execute function at the end of the scope.
      Parameters:
      function - runnable to be executed
  • Method Details