TST: Use try/except block to properly catch and handle the exception
Now no more warnings

- [x] closes #32951
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

