Replace bare excepts

This will fix http://trac.buildbot.net/ticket/2540.