move try catch to outside of switch statement and catch the correct exception.