|
-
Dec 2nd, 2010, 11:41 PM
#1
Thread Starter
Addicted Member
Consolidated Exceptions
I am trying to upload an excel file and my code reads the data of excel one by one. Unfortunately as we all know that excel doesn't restrict the data type for each cells, so there is a chance and possibility that my code can catch the exceptions.
How can I do this?
Code:
try
{
// do the statement
}
catch
{
// throw the exception, log it and then proceed to the next, don't stop.
// then prompt the users of all exceptions encountered.
}
I need to process more than 1,000 rows of data from excel. I don't want every time there is an exceptions the uploading process stops and fixed the problem then re-upload the data again. I want to consolidate first all the data with issues or exceptions then deal with it later after the uploading process done. Thank you guys in advance!
-
Dec 3rd, 2010, 06:51 AM
#2
Re: Consolidated Exceptions
you can loop on all the records once you uploaded the file and log them into string builder, if you find any problems print the string builder with the list of all the error and let the user fix them and then re-upload the file or fix the file online.
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Dec 4th, 2010, 04:34 AM
#3
Re: Consolidated Exceptions
Exception handling is technically for error's you can't test for in code. A try catch block as you have it will work but will not give great details (row, column etc of excel) that caused the error. It will give something like "dataType mismatch converting string to integer" or something which is difficult for the user to know which entry caused the error when reviewing the log.
If there is never going to be a review of the error log to fix the data then it doesn't matter. If the data needs correcting then I'd test each field for each row to ensure it conforms to your spec's if not log that and the row data then you have everything needed to call up the data and highlight problems.
The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded. 
-
Dec 4th, 2010, 09:30 AM
#4
Re: Consolidated Exceptions
Hello,
To be clear, in order to work on the excel file, your website will have to have completely uploaded the excel file onto the server, before it can work on it. So the upload process won't be cancelled. But rather, the processing of the file. Is that correct?
Depending on how you write you code, I would suggest that you try to use the built in .TryParse methods, such as Double.TryParse, DateTime.TryParse etc. That way, for each row, you can try and get the information out of the row, as you expect it, if you can't, then you can log an error, and handle it, but then continue the rest of the processing.
I think it would help if you show us a section of the code that you are trying to use, and then we can work from there.
Gary
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|