Changed exception handling when running with cprofile.