Wrong placement of error handling function