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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:37:33+00:00 2026-05-23T20:37:33+00:00

I have a snippet of code which checks if the network is available, and

  • 0

I have a snippet of code which checks if the network is available, and a machine is on an AD domain (Two if checks in && configuration). The other side of the coin, I have else if statements for each condition. In here, I throw relevant exceptions if they are not available (I don’t expect a machine to not be on the domain etc, this is not a routine event etc).

Problem is, race conditions. I have experienced a few race conditions so they are worth handling. In this case, after the check, the network may go down in which case the code will crash, so I need catch blocks. But then the catch blocks will catch the same type of exceptions as those thrown in the else blocks (those related to no domain or network).

Is this (same exception types in the else and catch blocks) a code smell or perfectly good coding?


EDIT: My code is such:

if (networkIsAvailable && MachineOnDomain) { }
else if !(networkIsAvailable) { throw new networknotavailablexception... }
else if !(machineNotOnDomain // you get the idea

This is surrounded by a try-catch, catching the same exception types.

Thanks

  • 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-23T20:37:33+00:00Added an answer on May 23, 2026 at 8:37 pm

    you can catch different types of exceptions:

    try{
        int x = 1;
        int y = 0;
        int z = x /y;
    }
    catch(ArgumentNullException){
        //this will never be reached
    }
    catch(DivideByZeroException){
        // this code will be reached
    }
    

    will this help in your case?

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

Sidebar

Related Questions

I have a snippet of code which looks at a network share. One error
In my project, I have created a code snippet which can be copied and
i have the following code snippet. in which i just want to return PartyName
I have this snippet of code which I am considering to simplfy: if (numberOfResults
I have the following code snippet which is working fine: ifstream NDSConfig( NDS.config )
I have the following snippet of code of which I do not have access
I have the following snippet of code which should increment a counter on a
I have a snippet of code like this: std::list<boost::shared_ptr<Point> > left, right; // ...
I have a snippet of code that I'm working with to filter rows in
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =

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.