Results 1 to 9 of 9
  1. #1
    chithu21 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Arrow While Loop is not iterating when it goes to the catch block

    I have the following code:
    while (iterator.hasNext()) {
    try{
    ...
    name = entry.getKey();
    conn = getConnection();
    SOP("ACTIVE");
    } catch(LDAPException e) {
    SOP("INACTIVE");
    continue;
    }
    }

    It works fine when the conection is ok....
    But when an exception is encountered, it not iterating.

    Anyone please help

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: While Loop is not iterating when it goes to the catch block

    You're not catching the exception that's being thrown then, or something else is happening in code you are not showing us.
    The following code shows that the above will work, if that is the exception being thrown:
    Java Code:
    public Scratch {
    public static void main(String args[]) {
    	for (int i = 0; i < 10; i++) {
    		try {
    			if (i % 2 == 1) {
    				throw new Exception();
    			}
    			System.out.println("no catch");
    		} catch (Exception ex) {
    			System.out.println("catch");
    			continue;
    		}
    	}
    }
    }
    (apologies for the tabs, they've just changed the formatting standard where I work)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    chithu21 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: While Loop is not iterating when it goes to the catch block

    I can't paste the entire code as it is huge:
    Here is what I am doing in the catch block

    while (iterator.hasNext()) {
    try{
    ...
    name = entry.getKey();
    conn = getConnection();
    SOP("ACTIVE");
    } catch(LDAPException e) {
    SOP("INACTIVE");
    try {
    ReleaseAndReInitateConnPool(dsName, ldapConnection,
    ldapConnectionPool, iconManager);
    } catch (FederationEngineException e1) {
    e1.printStackTrace();
    continue;
    }
    continue;
    }
    continue;
    }

  4. #4
    chithu21 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: While Loop is not iterating when it goes to the catch block

    The statements which i am mentioning inside the catch block works

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: While Loop is not iterating when it goes to the catch block

    And what output do you see?
    Because again:
    Java Code:
    	public static void main(String args[]) {
    		for (int i = 0; i < 10; i++) {
    			try {
    				if (i % 2 == 1) {
    					throw new Exception();
    				}
    				System.out.println("no catch");
    			} catch (Exception ex) {
    				try {
    					if (i % 3 == 0) {
    						throw new Exception();
    					}
    				} catch (Exception ex2) {
    					System.out.println("second catch");
    					continue;
    				}
    				System.out.println("catch");
    				continue;
    			}
    		}
    	}
    The above produces the expected output:
    no catch
    catch
    no catch
    second catch
    no catch
    catch
    no catch
    catch
    no catch
    second catch

    And that mimics yours.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    chithu21 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: While Loop is not iterating when it goes to the catch block

    All the statements gets executed ...Only the iteration is not happening

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: While Loop is not iterating when it goes to the catch block

    Then someting else is going on that is not obvious.
    Another exception that you might be eating, or there simply is nothing else in the iterator.
    None of which can be analysed witht he information provided so far.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    chithu21 is offline Member
    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Default Re: While Loop is not iterating when it goes to the catch block

    I have found another behaviour..
    The code works fine when i run in debug mode. But not in normal mode
    Any thoughts?

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default Re: While Loop is not iterating when it goes to the catch block

    Then something else is going on.
    You'll need to put together some small prgram that shows the problem, because this is going to be impossible to answer without more information and code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Stuck in continuous loop with try/catch block
    By ndsmith20 in forum New To Java
    Replies: 3
    Last Post: 02-03-2013, 01:26 AM
  2. Try Catch Block
    By Jackbower in forum New To Java
    Replies: 3
    Last Post: 05-06-2012, 07:00 AM
  3. try catch block issue
    By srivempala in forum Advanced Java
    Replies: 29
    Last Post: 07-22-2011, 06:45 PM
  4. Try/catch block
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-02-2009, 02:32 PM
  5. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 07:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •