Home >Java >javaTutorial >How to Handle Exceptions Thrown by SwingWorker's Future?

How to Handle Exceptions Thrown by SwingWorker's Future?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-28 22:12:11425browse

How to Handle Exceptions Thrown by SwingWorker's Future?

Can't get ArrayIndexOutOfBoundsException from Future and SwingWorker if thread starts Executor

SwingWorker does not expose any way to get an underlying exception. However, since SwingWorker provides a way to complete with a result using the done() method, you can rethrow the exception here, where it will be caught by the caller of the get() method on the Future.

// ...

@Override
protected void done() {
    if (str.equals("StartShedule")) {
        try {
            get();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        } catch (ExecutionException ee) {
            throw (ee).getCause();
        }
    }
}

The above is the detailed content of How to Handle Exceptions Thrown by SwingWorker's Future?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn