throw error in two places could crash by 'undefined' var