Better exception management in case of invalid environment