implemented method to thwo exception on error