Change exception handling to be backward compatible for Java<7.