Add some task test
This commit is contained in:
@@ -76,6 +76,11 @@ public abstract class Task<T> {
|
||||
// last exception
|
||||
private Exception exception;
|
||||
|
||||
/**
|
||||
* When task has been cancelled, task.exception will be null.
|
||||
*
|
||||
* @return the exception thrown during execution, possibly from dependents or dependencies.
|
||||
*/
|
||||
public final Exception getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,10 @@ public final class TaskExecutor {
|
||||
return future.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException | CancellationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException ignore) {
|
||||
// We have dealt with ExecutionException in exception handling and uncaught exception handler.
|
||||
} catch (CancellationException e) {
|
||||
Logging.LOG.log(Level.INFO, "Task " + firstTask + " has been cancelled.", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -202,8 +204,6 @@ public final class TaskExecutor {
|
||||
}
|
||||
task.onDone().fireEvent(new TaskEvent(this, task, true));
|
||||
taskListeners.forEach(it -> it.onFailed(task, e));
|
||||
} else if (e instanceof CancellationException || e instanceof RejectedExecutionException) {
|
||||
task.setException(e);
|
||||
} else {
|
||||
task.setException(e);
|
||||
exception = e;
|
||||
|
||||
Reference in New Issue
Block a user