Re: Infinite loop problem
I take it that the method getRectangle() is used inside of a loop, possibly in the main() method? Seeing the actual loop would probably help and I find it curious that you only catch the exception for r.height and not r.width. Another thing, Scanner.next() will make the scanner advance to the next input regardless of whether or not the input is correct. In other words if there is a InputMismatchException then the scanner will just revert to the last input and not ask for anymore input.
Re: Infinite loop problem
my apologies, I had taken out the loop before I posted the message. I didn't catch the exception for r.width because I wanted to get it right with r.height first and then just copy and paste it. I'm not quite sure what you mean by "scanner will just revert to the last input." This is the first thing that the user enters into the program. When a non-number character is entered it not only throws the error but also skips allowing the user to enter r.width.
Re: Infinite loop problem
I suppose saying that it will revert wasn't quite right. If there is a mismatch then the Scanner won't advance to the next input and, in this case, keep using a non-integer value causing an infinite loop. You can manually skip the incorrect input by calling Scanner.next() which will let the user input something else (hopefully a correct value).