com.hazelcast.util

## Class ExceptionUtil

- java.lang.Object
- - com.hazelcast.util.ExceptionUtil

-     public final class ExceptionUtil
      extends Object

  Contains various exception related utility methods.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `ExceptionUtil.RuntimeExceptionFactory` Interface used by rethrow/peel to wrap the peeled exception

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `fixAsyncStackTrace(Throwable asyncCause, StackTraceElement[] localSideStackTrace)` This method changes the given async cause, and it adds the also given local stacktrace. If the remoteCause is an `ExecutionException` and it has a non-null inner cause, this inner cause is unwrapped and the local stacktrace and exception message are added to the that instead of the given asyncCause itself.
    `static void` | `fixAsyncStackTrace(Throwable asyncCause, StackTraceElement[] localSideStackTrace, String localExceptionMessage)` This method changes the given async cause, and it adds the also given local stacktrace separated by the supplied exception message. If the remoteCause is an `ExecutionException` and it has a non-null inner cause, this inner cause is unwrapped and the local stacktrace and exception message are added to the that instead of the given remoteCause itself.
    `static RuntimeException` | `peel(Throwable t)`
    `static <T extends Throwable> Throwable` | `peel(Throwable t, Class<T> allowedType, String message)` Processes `Throwable t` so that the returned `Throwable`'s type matches `allowedType` or `RuntimeException`.
    `static <T extends Throwable> Throwable` | `peel(Throwable t, Class<T> allowedType, String message, ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)` Processes `Throwable t` so that the returned `Throwable`'s type matches `allowedType` or `RuntimeException`.
    `static RuntimeException` | `rethrow(Throwable t)`
    `static <T extends Throwable> RuntimeException` | `rethrow(Throwable t, Class<T> allowedType)`
    `static RuntimeException` | `rethrow(Throwable t, ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)`
    `static <T extends Throwable> RuntimeException` | `rethrowAllowedTypeFirst(Throwable t, Class<T> allowedType)` This rethrow the exception providing an allowed Exception in first priority, even it is a Runtime exception
    `static RuntimeException` | `rethrowAllowInterrupted(Throwable t)`
    `static <T> T` | `sneakyThrow(Throwable t)`
    `static String` | `toString(Throwable cause)` Converts a Throwable stacktrace to a String.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### toString

          public static String toString(Throwable cause)

      Converts a Throwable stacktrace to a String.
      Parameters:
        `cause` - the Throwable
      Returns:
        the String.

    - #### peel

          public static RuntimeException peel(Throwable t)

    - #### peel

          public static <T extends Throwable> Throwable peel(Throwable t,
                                                             Class<T> allowedType,
                                                             String message)

      Processes `Throwable t` so that the returned `Throwable`'s type matches `allowedType` or `RuntimeException`. Processing may include unwrapping `t`'s cause hierarchy, wrapping it in a `HazelcastException` or just returning the same instance `t` if it is already an instance of `RuntimeException`.
      Type Parameters:
        `T` - expected type of `Throwable`
      Parameters:
        `t` - `Throwable` to be peeled
        `allowedType` - the type expected to be returned; when `null`, this method returns instances of `RuntimeException`
        `message` - if not `null`, used as the message in the `HazelcastException` that may wrap the peeled `Throwable`
      Returns:
        the peeled `Throwable`

    - #### peel

          public static <T extends Throwable> Throwable peel(Throwable t,
                                                             Class<T> allowedType,
                                                             String message,
                                                             ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)

      Processes `Throwable t` so that the returned `Throwable`'s type matches `allowedType` or `RuntimeException`. Processing may include unwrapping `t`'s cause hierarchy, wrapping it in a `RuntimeException` created by using runtimeExceptionFactory or just returning the same instance `t` if it is already an instance of `RuntimeException`.
      Type Parameters:
        `T` - expected type of `Throwable`
      Parameters:
        `t` - `Throwable` to be peeled
        `allowedType` - the type expected to be returned; when `null`, this method returns instances of `RuntimeException`
        `message` - if not `null`, used as the message in `RuntimeException` that may wrap the peeled `Throwable`
        `runtimeExceptionFactory` - wraps the peeled code using this runtimeExceptionFactory
      Returns:
        the peeled `Throwable`

    - #### rethrow

          public static RuntimeException rethrow(Throwable t)

    - #### rethrow

          public static RuntimeException rethrow(Throwable t,
                                                 ExceptionUtil.RuntimeExceptionFactory runtimeExceptionFactory)

    - #### rethrow

          public static <T extends Throwable> RuntimeException rethrow(Throwable t,
                                                                       Class<T> allowedType)
                                                                throws T extends Throwable

      Throws:
        `T extends Throwable`

    - #### rethrowAllowedTypeFirst

          public static <T extends Throwable> RuntimeException rethrowAllowedTypeFirst(Throwable t,
                                                                                       Class<T> allowedType)
                                                                                throws T extends Throwable

      This rethrow the exception providing an allowed Exception in first priority, even it is a Runtime exception
      Throws:
        `T extends Throwable`

    - #### rethrowAllowInterrupted

          public static RuntimeException rethrowAllowInterrupted(Throwable t)
                                                          throws InterruptedException

      Throws:
        `InterruptedException`

    - #### sneakyThrow

          public static <T> T sneakyThrow(Throwable t)

    - #### fixAsyncStackTrace

          public static void fixAsyncStackTrace(Throwable asyncCause,
                                                StackTraceElement[] localSideStackTrace)

      This method changes the given async cause, and it adds the also given local stacktrace.
      If the remoteCause is an `ExecutionException` and it has a non-null inner cause, this inner cause is unwrapped and the local stacktrace and exception message are added to the that instead of the given asyncCause itself.
      Parameters:
        `asyncCause` - the async exception
        `localSideStackTrace` - the local stacktrace to add to the exception stacktrace

    - #### fixAsyncStackTrace

          public static void fixAsyncStackTrace(Throwable asyncCause,
                                                StackTraceElement[] localSideStackTrace,
                                                String localExceptionMessage)

      This method changes the given async cause, and it adds the also given local stacktrace separated by the supplied exception message.
      If the remoteCause is an `ExecutionException` and it has a non-null inner cause, this inner cause is unwrapped and the local stacktrace and exception message are added to the that instead of the given remoteCause itself.
      Parameters:
        `asyncCause` - the async exception
        `localSideStackTrace` - the local stacktrace to add to the exceptions stacktrace
        `localExceptionMessage` - a special exception message which is added to the stacktrace

Copyright © 2019. All rights reserved.