Untrapped ParseIntError exception on Win 10

#1

I started using Rust for the first time yesterday using VS Code on Win10, starting with an example from The Rust Programming Language book - Guessing Game.
The program generates a random number and you have to guess the number until a correct guess exits the loop. Invalid input, such as " 1w", should be caught and just continue the loop.

let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => continue, };

Instead, invalid input causes an exception "thread ‘main’ panicked…ParseIntError… ".

I tried the same code on Ubuntu using Eclipse and the code works correctly.

Do I have an incorrect setting in VS Code or is this a defect?

0 Likes

#2

Can we see your code and the full panic message? It is likely not a defect in VSCode, it may just be that you accidentally made a mistake copying it over.

0 Likes

#4

There must have been a problem on my system. It now works correctly.

0 Likes