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 8378415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:55:23+00:00 2026-06-09T15:55:23+00:00

A Pattern that I’ve seen a few times now and still am unsure if

  • 0

A Pattern that I’ve seen a few times now and still am unsure if it’s correct: I need to invoke some code on the SWT UI thread via Display.syncExec. The code that runs in the UI thread catches a checked exception and wants to propagate this exception to the waiting thread. The pattern looks like this:

SomeCheckedException[] exc = new SomeCheckedException[] { null };
display.syncExec(new Runnable(){
   public void run(){
      try {
         new Work().something();
      } catch (SomeCheckedException e){
         exc[0] = e;
      }
   }
});

if (exc[0] != null){
 //..
}

Even if there’s no real concurrency here, I still think that this is not really safe in terms of visibility: It could well happen that the UI thread stores an exception, but the invoking thread won’t see this and still read ‘null’ when accessing the array after taking control again. Am I right? Is the best way then just to catch SWTException and check its throwable field via instanceof? EDIT: Hm, that won’t work so easy if it’s a checked exception. I’d need to throw the SWTException from the catch block myself. Better solutions?

Thanks for your help and comments.

  • 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-06-09T15:55:24+00:00Added an answer on June 9, 2026 at 3:55 pm

    This is the sort of case AtomicReference was made for:

      void foo() throws SomeCheckedException {
        final AtomicReference<SomeCheckedException> exRef = new AtomicReference<>();
        display.syncExec(new Runnable() {
          public void run() {
            try {
              new Work().something();
            } catch (SomeCheckedException e) {
              exRef.set(e);
            }
          }
        });
        SomeCheckedException ex = exRef.get();
        if (ex != null) {
          throw ex;
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following small example implements a singleton pattern that I've seen many times: #include
Is there a pattern that I could apply to refactor this code? The only
I need a regex pattern that validates IP addresses. This is easy enough to
I need a pattern that will traverse the document and get me all links
I'm concerned that I might be using a code pattern that leaks memory. Here's
I need a regex pattern that validates a password format. The rules are: Minimum
I'm trying to figure out the correct approach (and pattern) that my current problem
There is a pattern that happens every now and then. I have a method
I have a Regex pattern that matches data I need to parse exactly as
I have a loan pattern that applies a function n times where 'i' is

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.