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 Summary

    Constructors
    Constructor
    Description
    Create a scope guard that will execute function at the end of the scope.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    performs the function
    void
    Disarms the scope guard, so that the function F will not be called at the end of the scope.
    The qScopeGuard function can be used to call a function at the end of the scope.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • QScopeGuard

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