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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:44:54+00:00 2026-05-23T00:44:54+00:00

How should I handle InterruptedException while joining other threads, assuming I don’t actually anticipate

  • 0

How should I handle InterruptedException while joining other threads, assuming I don’t actually anticipate being interrupted, and there is no sensible thing to do? Just swallow the exception?

try
{
    t.join();
    u.join();
}
catch (InterruptedException e)
{
    // should not happen
}

Or should I put each join in its separate try/catch, so if an InterruptedExeption does happen while joining t, at least u gets a chance of being joined?

try
{
    t.join();
}
catch (InterruptedException e)
{
    // should not happen
}
try
{
    u.join();
}
catch (InterruptedException e)
{
    // should not happen
}

Or should I defensively swallow the exceptions in a loop, so I will eventually join both threads, even if some malicious guy tries to interrupt me?

while (true)
{
    try
    {
        t.join();
        break;
    }
    catch (InterruptedException e)
    {
        // no way, Jose!
    }
}
while (true)
{
    try
    {
        u.join();
        break;
    }
    catch (InterruptedException e)
    {
        // no way, Jose!
    }
}

On a side note, is there any case where InterruptedExeption doesn’t make my code look ugly? 🙂

  • 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-23T00:44:55+00:00Added an answer on May 23, 2026 at 12:44 am

    If something shouldn’t happen, you probably want to know if it ever does happen – and the best way of making it obvious is often to throw a RuntimeException of some description (e.g. IllegalStateException). If you’re not anticipating the possibility of being interrupted, that suggests the system is in a state you’re not really happy to support, so I wouldn’t then try to keep going – aborting quickly is often the best option here.

    You may want to write a helper method which does this for you, to make the calling code cleaner.

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

Sidebar

Related Questions

Is there a defined behavior for how regular expressions should handle the capturing behavior
I'm asking this because I really don't know where I should handle events of
Is using view in db design right method or we should handle it code
I have googled a bit for how I should handle security in a web
How should I handle image uploading using PHP? How should I handle the chmod
What is the most secure way to handle forgotten passwords/password resets? Should I email
I'm writing a messaging layer that should handle communication with a third party API.
I found this regarding how the C preprocessor should handle string literal concatenation (phase
I can't understand what sort of exceptions I should handle 'here and now', and
I'm developing a website using ASP.NET MVC. The website should handle multiple languages. I

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.