Catch any exceptions thrown by getEnv; fixes #1704