Fix catching the wrong type of exception