2 Replies - 1033 Views - Last Post: 09 June 2014 - 12:36 PM Rate Topic: -----

#1 sv121  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-June 14

how to use try catch in do while loop java

Posted 09 June 2014 - 12:27 PM

I wrote a program using switchcase.I used do while to show the menu to the user until the user decides to exit the menu.I used try catch to prevent ant exception and it worked properly.But i got one problem.When exception occurs,desired msg is printed but i am unable to display the menu to the user.So user wont be able to continue after an exception is caused.Pls help me.I hope u guys give me an example along with its explanation.
Is This A Good Question/Topic? 0
  • +

Replies To: how to use try catch in do while loop java

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Re: how to use try catch in do while loop java

Posted 09 June 2014 - 12:35 PM

You've probably put your while loop inside you try catch block so the while loop exits when the exception is thrown. You want to do it the other way around.
Was This Post Helpful? 0
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1822
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to use try catch in do while loop java

Posted 09 June 2014 - 12:36 PM

We will need to see your code to know what you are doing. But if the try..catch blocks are inside the loop, and the catch block make the condition for the loop to be true again, then you will have another iteration of the loop.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1