While uploading a file, I'm getting an exception however still upload resta

While uploading a file, I’m getting an exception on server side while processing the data and for the first time it goes in FileUploadHandler and restarts the file uploading however on second iteration it goes inside Upload class and calls endUpload(). Any idea how this can be resolved?