protect against bad input

I also have the scanner as a dependency injection instead. But I found no information how to properly close this scanner.