All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.bpmcrafters.processengine.worker.registrar.ExceptionResolver.kt Maven / Gradle / Ivy

There is a newer version: 0.1.0
Show newest version
package dev.bpmcrafters.processengine.worker.registrar

import java.lang.reflect.InvocationTargetException
import java.util.concurrent.ExecutionException

/**
 * Utility to help unwrapping exceptions.
 * @since 0.0.3
 */
class ExceptionResolver {

  /**
   * Unpack the exception.
   * @param e thrown exception.
   * @return unwrapped cause.
   */
  fun getCause(e: Throwable): Throwable {
    return when (e) {
      is ExecutionException -> if (e.cause != null) {
        getCause(e.cause!!)
      } else {
        e
      }
      is InvocationTargetException -> if (e.targetException != null) {
        getCause(e.targetException!!)
      } else if (e.cause != null) {
        getCause(e.cause!!)
      } else {
        e
      }
      else -> e
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy