To not have to check which exception has been thrown, you might want to make the try block smaller and divide it into two with each of them catching their own exception. I don't think that the last code in here could case an IOError, or?