Class ExceptionSwallower

java.lang.Object
com.norconex.crawler.core.util.ExceptionSwallower

public final class ExceptionSwallower extends Object
  • Method Details

    • swallow

      public static void swallow(FailableRunnable<Exception> runnable)
      Ensures that any exceptions thrown while executing are swallowed and a default message logged.
      Parameters:
      runnable - the code to execute
    • swallow

      public static void swallow(FailableRunnable<Exception> runnable, String msg)
      Ensures that any exceptions thrown while executing are swallowed and a custom message logged.
      Parameters:
      runnable - the code to execute
      msg - message to log when there is an exception
    • swallowQuietly

      public static void swallowQuietly(FailableRunnable<Exception> runnable)
      Ensures that any exceptions thrown while executing are swallowed and no messages are logged about the exception.
      Parameters:
      runnable - the code to execute
    • close

      public static void close(AutoCloseable... closeables)
      Ensures that any exceptions thrown while closing the supplied resource are swallowed and a default message logged. null arguments are ignored.
      Parameters:
      closeables - one ore more resources to close
    • close

      public static void close(AutoCloseable closeable, String msg)
      Ensures that any exceptions thrown while closing the supplied resource are swallowed and a custom message logged.
      Parameters:
      closeable - resource to close
      msg - message to display in case of failure to close
    • closeQuietly

      public static void closeQuietly(AutoCloseable... closeables)
      Ensures that any exceptions thrown while closing the supplied resource are swallowed and no messages are logged about the exception.
      Parameters:
      closeables - one or more resources to close
    • runWithInterruptClear

      public static void runWithInterruptClear(Runnable runnable)
      Runs the given runnable, clearing the thread's interrupt flag before execution and restoring it after if it was set. Useful for shutdown/close logic that must not be interrupted.
      Parameters:
      runnable - the code to execute
    • runWithInterruptClearEx

      public static void runWithInterruptClearEx(FailableRunnable<Exception> runnable) throws Exception
      Runs the given FailableRunnable, clearing the thread's interrupt flag before execution and restoring it after if it was set. Useful for shutdown/close logic that must not be interrupted. Any thrown exception is propagated.
      Parameters:
      runnable - the code to execute
      Throws:
      Exception - if the runnable throws