Results 1 to 4 of 4

Thread: Consolidated Exceptions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    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!

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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

  3. #3
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    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.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width