changed console.error to throw