Top Description Inners Constructors Methods
org.eclipse.jetty.util

public Class ExceptionUtil

extends Object
Class Inheritance
Imports
java.lang.reflect.Constructor, java.util.Arrays, .List, java.util.concurrent.CompletableFuture, .ExecutionException, org.eclipse.jetty.util.thread.Invocable

Exception (or rather Throwable utility methods.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addSuppressedIfNotAssociated(Throwable
The main Throwable
throwable
,
Throwable
The Throwable to suppress if it is not associated.
suppressed
)

Add a suppressed exception if it is not associated.

public static boolean

Returns:

true iff the exceptions are not associated by being the same instance, sharing a cause or one suppressing the other.
areNotAssociated
(Throwable
A Throwable or null
t1
,
Throwable
Another Throwable or null
t2
)

Check if two Throwables are associated.

public static <
The type of the Throwable to be returned
T extends Throwable
>
T

Returns:

A Throwable of type T or null.
as
(Class<T>
The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.
type
,
Throwable
The Throwable or null
throwable
)

Convert a Throwable to a specific type by casting or construction on a new instance.

public static Throwable

Returns:

t1 with t2 suppressed, or null.
combine
(Throwable
A Throwable or null
t1
,
Throwable
Another Throwable or null
t2
)

Combine two, possible null, Throwables in a style to facilitate handling multiple exceptions that are accumulated as suppressed exceptions.

public static <
The type of the CompletableFuture
T
>
T

Returns:

The value from calling CompletableFuture#get()
get
(CompletableFuture<T>
The future to get from.
completableFuture
)

Get from a CompletableFuture and convert any uncheck exceptions to RuntimeException.

public static void
ifExceptionThrow(Throwable
The Throwable to throw or null.
throwable
)

Throw a Throwable as a checked Exception if it cannot be thrown as unchecked.

public static <
The type of the Throwable to be thrown if throwable is not null.
T extends Throwable
>
void
ifExceptionThrowAllAs(Class<T>
The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.
type
,
Throwable
A Throwable or null.
throwable
)

Throw a Throwable as a specific type, casting or construction as required.

public static <
The type of the Throwable to be thrown if throwable is not null.
T extends Throwable
>
void
ifExceptionThrowAs(Class<T>
The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.
type
,
Throwable
A Throwable or null.
throwable
)

Throw a Throwable as a specific type, casting or construction as required.

public static void
ifExceptionThrowUnchecked(Throwable
The Throwable to throw or null.
throwable
)

Throw a Throwable as an unchecked Exception.

public static <
of type Throwable
T extends Throwable
>
T

Returns:

the original throwable with suppressed errors
withSuppressed
(T
the throwable
t
,
List<Throwable>
the list of errors
errors
)

Decorate a Throwable with the suppressed errors and return it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ExceptionUtilback to summary
private ExceptionUtil()

Method Detail

addSuppressedIfNotAssociatedback to summary
public static void addSuppressedIfNotAssociated(Throwable throwable, Throwable suppressed)

Add a suppressed exception if it is not associated.

Parameters
throwable:Throwable

The main Throwable

suppressed:Throwable

The Throwable to suppress if it is not associated.

See Also
areNotAssociated(Throwable, Throwable)
areNotAssociatedback to summary
public static boolean areNotAssociated(Throwable t1, Throwable t2)

Check if two Throwables are associated.

Parameters
t1:Throwable

A Throwable or null

t2:Throwable

Another Throwable or null

Returns:boolean

true iff the exceptions are not associated by being the same instance, sharing a cause or one suppressing the other.

asback to summary
public static <T extends Throwable> T as(Class<T> type, Throwable throwable) throws IllegalArgumentException

Convert a Throwable to a specific type by casting or construction on a new instance.

Parameters
<T>
The type of the Throwable to be returned
type:Class<T>

The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.

throwable:Throwable

The Throwable or null

Returns:T

A Throwable of type T or null.

Exceptions
IllegalArgumentException:
if the passed type cannot be constructed with a cause.
combineback to summary
public static Throwable combine(Throwable t1, Throwable t2)

Combine two, possible null, Throwables in a style to facilitate handling multiple exceptions that are accumulated as suppressed exceptions. This is freqently used in the following pattern:

    Throwable multiException = null;
    for (Runnable task : manyThings)
    {
        try
        {
            task.run();
        }
        catch(Throwable t)
        {
            multiException = multiException.combine(multiException, t)
        }
    }
    MultiException.ifExceptionalThrow(multiException);
Parameters
t1:Throwable

A Throwable or null

t2:Throwable

Another Throwable or null

Returns:Throwable

t1 with t2 suppressed, or null.

getback to summary
public static <T> T get(CompletableFuture<T> completableFuture)

Get from a CompletableFuture and convert any uncheck exceptions to RuntimeException.

Parameters
<T>
The type of the CompletableFuture
completableFuture:CompletableFuture<T>

The future to get from.

Returns:T

The value from calling CompletableFuture#get()

Exceptions
RuntimeException:
if the call to CompletableFuture#get() throws.
ifExceptionThrowback to summary
public static void ifExceptionThrow(Throwable throwable) throws Error, Exception

Throw a Throwable as a checked Exception if it cannot be thrown as unchecked.

Parameters
throwable:Throwable

The Throwable to throw or null.

Exceptions
Error:
If the passed Throwable is an Error.
Exception:
Otherwise, if the passed Throwable is not null.
ifExceptionThrowAllAsback to summary
public static <T extends Throwable> void ifExceptionThrowAllAs(Class<T> type, Throwable throwable) throws Throwable-:T

Throw a Throwable as a specific type, casting or construction as required.

Parameters
<T>
The type of the Throwable to be thrown if throwable is not null.
type:Class<T>

The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.

throwable:Throwable

A Throwable or null.

Exceptions
Throwable-:T:
Thrown in throwable is not null and neither an Error nor RuntimeException.
ifExceptionThrowAsback to summary
public static <T extends Throwable> void ifExceptionThrowAs(Class<T> type, Throwable throwable) throws Error, RuntimeException, Throwable-:T, IllegalArgumentException

Throw a Throwable as a specific type, casting or construction as required.

Parameters
<T>
The type of the Throwable to be thrown if throwable is not null.
type:Class<T>

The type of the Throwable to be thrown. It must have a constructor that takes a Throwable as a cause.

throwable:Throwable

A Throwable or null.

Exceptions
Error:
If the passed Throwable is an Error.
RuntimeException:
If the passed Throwable is a RuntimeException.
Throwable-:T:
Thrown in throwable is not null and neither an Error nor RuntimeException.
IllegalArgumentException:
if the passed type cannot be constructed with a cause.
ifExceptionThrowUncheckedback to summary
public static void ifExceptionThrowUnchecked(Throwable throwable) throws Error, RuntimeException

Throw a Throwable as an unchecked Exception.

Parameters
throwable:Throwable

The Throwable to throw or null.

Exceptions
Error:
If the passed Throwable is an Error.
RuntimeException:
Otherwise, if the passed Throwable is not null.
withSuppressedback to summary
public static <T extends Throwable> T withSuppressed(T t, List<Throwable> errors)

Decorate a Throwable with the suppressed errors and return it.

Parameters
<T>
of type Throwable
t:T

the throwable

errors:List<Throwable>

the list of errors

Returns:T

the original throwable with suppressed errors

org.eclipse.jetty.util back to summary

public Class ExceptionUtil.MultiException

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Throwable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public <T extends Throwable> void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_multiExceptionback to summary
private Throwable _multiException

Constructor Detail

MultiExceptionback to summary
public MultiException()

Method Detail

addback to summary
public void add(Throwable t)
callAndCatchback to summary
public void callAndCatch(Invocable.Callable task)
ifExceptionThrowback to summary
public void ifExceptionThrow() throws Exception
ifExceptionThrowAsback to summary
public <T extends Throwable> void ifExceptionThrowAs(Class<T> type) throws Class-:T
ifExceptionThrowRuntimeback to summary
public void ifExceptionThrowRuntime()