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

  • Home
  • SEARCH
  • 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 1024135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:44:03+00:00 2026-05-16T11:44:03+00:00

I have something similar to this. void func() { try { //socket disconnects in

  • 0

I have something similar to this.

void func() {
  try {
    //socket disconnects in middle of ..parsing packet..
  } catch(Exception ex) {
   if(!ex.getMessage().toString().equals("timeout") || !ex.getMessage().toString().equals("Connection reset")) {
     debug("Exception (run): " + ex.getMessage());
     ex.printStackTrace();
  }
}

Why is it that when I get a connection reset exception or a timeout exception, it still goes inside the condition. I tried without toString and with no luck.

  • 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-16T11:44:03+00:00Added an answer on May 16, 2026 at 11:44 am

    You shouldn’t catch all exceptions and then test the error message of the exception. Instead only catch those exceptions that you intend to handle – for example SocketTimeoutException.

    catch (SocketTimeoutException ex)
    {
        // Do something...
    }
    

    With your current code you may be catching some other type of exception that you weren’t expecting. Currently you will just ignore this exception, not even logging it. This can make it very difficult to debug what is going on. If you have an exception that you can’t handle you should either rethrow it or log it.

    I want to catch all exceptions

    If you really want to do that then you can write your code as follows:

    catch (SocketTimeoutException ex)
    {
        // Do something specific for SocketTimeoutException.
    }
    catch (Exception ex)
    {
        // Do something for all other types of exception.
    }
    

    Regarding your specific error, you have written:

    !a.equals(b) || !a.equals(c)
    

    This expression always evaluates to true. What you meant was:

    !a.equals(b) && !a.equals(c)
    

    Or equivalently:

    !(a.equals(b) || a.equals(c))
    

    Note that by rewriting your code as I suggested above you completely avoid having to write this complicated boolean expression.

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

Sidebar

Related Questions

I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
This is for practise. I try to build something similar to NSLog. Currently I
I wondering if something similar to this is possible. Basically, I have a templated
I have a file with function signatures like this: void something(float a, int b,
I have a function similar to this: void foo(obj ary[], int arysize) { for
I have something similar to that: <table> <tr> <td>Hello,<br/>World!</td> </tr> </table> Both lines Hello,
i have something similar to the following... used a python script to JSON to
I am just trying to find out that does puppet have something similar to
I have an ASP.NET web site with something similar to the following code: .aspx
We currently have an ant task that contains something similar to the following: <filelist

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.