This commit is contained in:
huanghongxun 2020-08-27 11:19:52 +08:00
parent cafcb74e22
commit 674dfca34d
4 changed files with 10 additions and 2 deletions

View File

@ -18,11 +18,12 @@
package org.jackhuang.hmcl.download.game; package org.jackhuang.hmcl.download.game;
import org.jackhuang.hmcl.game.Library; import org.jackhuang.hmcl.game.Library;
import org.jetbrains.annotations.NotNull;
public class LibraryDownloadException extends Exception { public class LibraryDownloadException extends Exception {
private final Library library; private final Library library;
public LibraryDownloadException(Library library, Throwable cause) { public LibraryDownloadException(Library library, @NotNull Throwable cause) {
super("Unable to download library " + library, cause); super("Unable to download library " + library, cause);
this.library = library; this.library = library;

View File

@ -37,6 +37,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.jar.*; import java.util.jar.*;
import java.util.logging.Level; import java.util.logging.Level;
@ -95,6 +96,8 @@ public class LibraryDownloadTask extends Task<Void> {
Exception t = task.getException(); Exception t = task.getException();
if (t instanceof DownloadException) if (t instanceof DownloadException)
throw new LibraryDownloadException(library, t.getCause()); throw new LibraryDownloadException(library, t.getCause());
else if (t == null)
throw new CancellationException();
else else
throw new LibraryDownloadException(library, t); throw new LibraryDownloadException(library, t);
} else { } else {

View File

@ -17,6 +17,8 @@
*/ */
package org.jackhuang.hmcl.task; package org.jackhuang.hmcl.task;
import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -26,7 +28,7 @@ public class DownloadException extends IOException {
private final URL url; private final URL url;
public DownloadException(URL url, Throwable cause) { public DownloadException(URL url, @NotNull Throwable cause) {
super("Unable to download " + url + ", " + cause.getMessage(), requireNonNull(cause)); super("Unable to download " + url + ", " + cause.getMessage(), requireNonNull(cause));
this.url = url; this.url = url;

View File

@ -31,6 +31,7 @@ import org.jackhuang.hmcl.util.function.ExceptionalConsumer;
import org.jackhuang.hmcl.util.function.ExceptionalFunction; import org.jackhuang.hmcl.util.function.ExceptionalFunction;
import org.jackhuang.hmcl.util.function.ExceptionalRunnable; import org.jackhuang.hmcl.util.function.ExceptionalRunnable;
import org.jackhuang.hmcl.util.function.ExceptionalSupplier; import org.jackhuang.hmcl.util.function.ExceptionalSupplier;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -131,6 +132,7 @@ public abstract class Task<T> {
* *
* @return the exception thrown during execution, possibly from dependents or dependencies. * @return the exception thrown during execution, possibly from dependents or dependencies.
*/ */
@Nullable
public final Exception getException() { public final Exception getException() {
return exception; return exception;
} }