You should place the break;
after the code is executed successfully.
do {
try {
Blob b = new Blob(id);
break;
}
catch (Exception e) {
System.out.println(e);
}
System.out.println("Enter a different ID: ");
id = scan.nextInt();
} while(true);
So each time the loop would reach the end of its body, it would break out of the loop. You only should break after the blob
is created successfully. Although I dont see why you put a break
anyway. The while
loop can check if the entered input was valid and simply stop the loop.
I modified the while
in a do-while
loop... By using true
the loop will run forever, unless no exception is thrown by the constructor... This makes the code more generic (if you modify the conditions of the blob-construction, you don't have to modify the condition of the while
loop).