Class Exceptions

java.lang.Object
dev.langchain4j.internal.Exceptions

public class Exceptions extends Object
Utility methods for creating common exceptions.
  • Method Details

    • illegalArgument

      public static IllegalArgumentException illegalArgument(String format, Object... args)
      Constructs an IllegalArgumentException with the given formatted result.

      Equivalent to new IllegalArgumentException(String.format(format, args)).

      Parameters:
      format - the format string
      args - the format arguments
      Returns:
      the constructed exception.
    • runtime

      public static RuntimeException runtime(String format, Object... args)
      Constructs an RuntimeException with the given formatted result.

      Equivalent to new RuntimeException(String.format(format, args)).

      Parameters:
      format - the format string
      args - the format arguments
      Returns:
      the constructed exception.
    • unwrapCompletionException

      public static Throwable unwrapCompletionException(Throwable throwable)
      Unwraps the underlying cause of a CompletionException or ExecutionException, returning any other throwable unchanged.

      CompletableFuture composition wraps failures in a CompletionException, while the blocking accessor Future.get() wraps them in an ExecutionException. Neither wrapper is a domain exception - they are artifacts of the asynchronous machinery. This peels those wrappers (including nested layers, e.g. a CompletionException around an ExecutionException that leaked in from a blocking Future.get() bridged into the pipeline) so callers can inspect or map the real exception.

      Parameters:
      throwable - the throwable to unwrap.
      Returns:
      the innermost cause once no CompletionException/ExecutionException wrapper with a non-null cause remains, otherwise throwable unchanged.
    • unwrapRuntimeException

      public static Throwable unwrapRuntimeException(Exception e)
    • unchecked

      public static <T> T unchecked(Callable<T> callable)