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

How to Handle Exceptions Thrown by SwingWorker's Future?

Patricia Arquette
Release: 2024-12-28 22:12:11
Original
442 people have browsed it

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();
        }
    }
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template