Added exception to preferences.close()