Class Exceptions
java.lang.Object
dev.langchain4j.internal.Exceptions
Utility methods for creating common exceptions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IllegalArgumentExceptionillegalArgument(String format, Object... args) Constructs anIllegalArgumentExceptionwith the given formatted result.static voidrestoreInterruptIfInterrupted(Throwable throwable) Sets the interrupt flag of the current thread again ifthrowableis anInterruptedException, so that catching it as aThrowable(for example one thrown without being declared) does not lose the interrupt.static RuntimeExceptionConstructs anRuntimeExceptionwith the given formatted result.static <T> Tstatic ThrowableunwrapCompletionException(Throwable throwable) Unwraps the underlying cause of aCompletionExceptionorExecutionException, returning any other throwable unchanged.static Throwable
-
Method Details
-
illegalArgument
Constructs anIllegalArgumentExceptionwith the given formatted result.Equivalent to
new IllegalArgumentException(String.format(format, args)).- Parameters:
format- the format stringargs- the format arguments- Returns:
- the constructed exception.
-
runtime
Constructs anRuntimeExceptionwith the given formatted result.Equivalent to
new RuntimeException(String.format(format, args)).- Parameters:
format- the format stringargs- the format arguments- Returns:
- the constructed exception.
-
unwrapCompletionException
Unwraps the underlying cause of aCompletionExceptionorExecutionException, returning any other throwable unchanged.CompletableFuturecomposition wraps failures in aCompletionException, while the blocking accessorFuture.get()wraps them in anExecutionException. Neither wrapper is a domain exception - they are artifacts of the asynchronous machinery. This peels those wrappers (including nested layers, e.g. aCompletionExceptionaround anExecutionExceptionthat leaked in from a blockingFuture.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/ExecutionExceptionwrapper with a non-null cause remains, otherwisethrowableunchanged.
-
restoreInterruptIfInterrupted
Sets the interrupt flag of the current thread again ifthrowableis anInterruptedException, so that catching it as aThrowable(for example one thrown without being declared) does not lose the interrupt. -
unwrapRuntimeException
-
unchecked
-