On 8/19/20 1:44 PM, Flade wrote:
Hi everyone! I'm trying to do error handling (with the try block) and when I give a wrong value to the variable (it is an integer and I give a non-number value), then It doesn't let me re get input. The code:


int x;

bool not_accepted = false;

while (!not_accepted) {

     try {

         write("x: ");

         readf("%d\n", x);

         not_accepted = true;

} catch (Exception msg) {

         writeln("Please give a right coordinate");

     }

Probably readf stops as soon as it encounters an error, meaning that your input is still present.

Try instead getting a line via readln, and then trying to read that into your expected input.

-Steve

Reply via email to