It helps to catch the right exception.

Credit: sethyx