Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4550134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:27:21+00:00 2026-05-21T16:27:21+00:00

I wish to handle Exceptions in a meaningful way in a Swing application. The

  • 0

I wish to handle Exceptions in a meaningful way in a Swing application.

The following is inside an actionPerformed method. The UiUtils#showError displays a JOptionPane with a button that shows/hides the stack trace. ApplicationException is a custom class to translate low level Exceptions to something a user would understand.

One issue is that I’m not sure how to handle a NullPointerException that propagates up if a user doesn’t select a file in the JFileChooser before this code. The exportData method purposefully checks for null on entry so no file handling is done.

Also, it seems that it would be a good approach to wrap a low level Exception (from the data layer for example). I’d like to modify ApplicationException to keep an instance instead of doing this in the showError method.

Finally, there’s one thing that’s bothering me and that’s the possibility that a few Exceptions could happen simultaneously. I have no idea how to handle this so I’m open to any suggestions.

try {
    dataService.exportData(list, selectedFile);
} catch (IOException e) {
    UiUtils.showError(new ApplicationException("Input/Ouput error"), e );
} finally {

    if( list == null){
        UiUtils.showError(new ApplicationException("No data to export"), null );
    }

    if( selectedFile == null ){
        UiUtils.showError(new ApplicationException("No file selected"), null );
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:27:22+00:00Added an answer on May 21, 2026 at 4:27 pm

    To catch NullPointerException (or any RuntimeException for that matter) as well as your IOExceptionjust catch the most general exception type:

    try {
       dataService.exportData(list, selectedFile);
    } catch (Exception e) {
       UiUtils.showError(new ApplicationException(e), e );
    } finally {
      ...
    }
    

    You can wrap the original exception into your ApplicationException by adding it as a “cause” parameter to the constructor, e.g.:

    public class ApplicationException extends RuntimeException {
    
       public ApplicationException(Exception cause) {
           super(cause);
       }
    
       ...
    }
    

    Then the original exception would be always available via the getCause() method.

    If you program is not multithreaded, I wouldn’t worry about simultaneous exceptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application in which I wish to handle different currency formats,
I have an Async method returning a Task. I also wish to offer a
In the microblogging application I am developing I wish to show an user image
I am working on a WPF application and I wish to open sip:Username@company.com links.
I wish to know when another application finishes editing a file. I am aware
I wish to embed a very light HTTP server in my Java Swing app
I have a wpf application, which consumes wcf service. I wish to catch any
I've got the following problem. After starting, application works fine - even after changing
I wish Subversion had a better way of moving tags. The only way that
How can mouse events be captured on highcharts axis label? I wish to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.