Throw exception when it occurs and fix logic to print error line