This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am working on a project for my java class that has to do with exception handling. What i am trying to do is use a try catch block with multiple catches. when i run my program it just puts out an infinite loop. What it has to do is catch the InputMismatchException and then loop back to have the user retype two integers. I also have to define my own exception for dividing by zero...but that�s a question for later...please help...code below...thanks ----------------------------------------------------------------------------
EDIT by mw: Added Code Tags. [ February 07, 2007: Message edited by: marc weber ]
Jason Mackie
Greenhorn
Joined: Feb 07, 2007
Posts: 17
posted
0
wow sorry about that...i had everything indented and everything...guess this forum didnt like it
Originally posted by Jason Mackie: ...when i run my program it just puts out an infinite loop. What it has to do is catch the InputMismatchException and then loop back to have the user retype two integers...
Welcome to JavaRanch!
When the InputMismatchException is thrown, the Scanner does not advance, so it's still trying to scan whatever input caused the exception. To advance the Scanner past the "bad" input, try adding the following as the first line of your catch block...
scan.nextLine();
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Jason Mackie
Greenhorn
Joined: Feb 07, 2007
Posts: 17
posted
0
awesome thanks marc that worked...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.