Example usage for java.nio.file NoSuchFileException addSuppressed

List of usage examples for java.nio.file NoSuchFileException addSuppressed

Introduction

In this page you can find the example usage for java.nio.file NoSuchFileException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:org.sakuli.utils.ResourceHelper.java

/**
 * Resolves a resource from the Classpath.
 *
 * @param classDef          a instance of {@link Class}
 * @param classPathResource resource string like e.g. "/filename.file".
 * @param exceptionMessage  custom exception message, if file couldn't resolved.
 * @return a {@link Path} object of the classpath resource.
 * @throws NoSuchFileException/* w  w  w. ja  va  2s  .  c  o m*/
 */
public static Path getClasspathResource(Class<?> classDef, String classPathResource, String exceptionMessage)
        throws NoSuchFileException {
    try {
        return Paths.get(classDef.getResource(classPathResource).toURI());
    } catch (FileSystemNotFoundException | URISyntaxException | NullPointerException e) {
        NoSuchFileException exc = new NoSuchFileException(classPathResource, null, exceptionMessage);
        exc.addSuppressed(e);
        throw exc;
    }
}