Announcement Announcement Module
Collapse
No announcement yet.
Plugging customized message to FlatFileParseException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plugging customized message to FlatFileParseException

    How do i attach the customized exception message ("File is not comma delimited") to the FlatFileParseException?

    My class ABCMapper is as shown below... Do i need to implement ItemReader subclass?

    ABCMapper class
    {
    String strFieldSetNames[] = fs.getNames();
    try
    {
    file.setPrice(fs.readBigDecimal("price"));
    file.setPromoDate(fs.readDate("prmoDate"));
    }
    catch(RuntimeException runEx)
    {
    String strMessage = "";
    if(fs.getFieldCount() != strFieldSetNames.length)
    {
    //Add Customized message to the FlatFileParseException }
    }
    }
    Last edited by springforever; Apr 10th, 2008, 10:02 AM.

  • #2
    It seems like you would get an error that the line is not delimited in the DelimitedLineTokenizer before you ever even get to the point where a FieldSet is created. If I were you, I would wrap the tokenizer and throw a more specific exception. It will still be wrapped in the FlatFileParseException, but the cause will be there and should be determinable.

    Comment


    • #3
      Originally posted by lucasward View Post
      It seems like you would get an error that the line is not delimited in the DelimitedLineTokenizer before you ever even get to the point where a FieldSet is created. If I were you, I would wrap the tokenizer and throw a more specific exception. It will still be wrapped in the FlatFileParseException, but the cause will be there and should be determinable.
      Good data should be in the format "Id,Price,PromoDate".

      File Data:
      123,0.22 2008-03-28

      It is treating "0.23 2008-04-09" as price (that's why i thought of using if(fs.getFieldCount() != strFieldSetNames.length)
      ) and FieldSet does get created. Exception is "java.lang.IllegalArgumentException: Unparseable number: 0.22 2008-03-28, name: [Price]"............

      How do i wrap the tokenizer?

      Comment


      • #4
        I understand what you're trying to do much better, but it still doesn't quite make sense to me.

        When you try and read from the third index (or even using the column name) you'll get an IndexOutOfBoundsException because there isn't a third value in the array. I could perhaps understand wanting to catch that and rethrow as something custom, although 'The File is not comma delimited' doesn't make too much sense to me. Just because one file is formatted incorrectly or is missing some data doesn't mean the whole file is necessarily formatted incorrectly. If you did decide to throw a custom exception, it will still be the 'cause' of the FlatFileParseException, so I don't see why you would want to replace the much more informative message.

        Comment


        • #5
          Originally posted by lucasward View Post
          I understand what you're trying to do much better, but it still doesn't quite make sense to me.

          When you try and read from the third index (or even using the column name) you'll get an IndexOutOfBoundsException because there isn't a third value in the array. I could perhaps understand wanting to catch that and rethrow as something custom, although 'The File is not comma delimited' doesn't make too much sense to me. Just because one file is formatted incorrectly or is missing some data doesn't mean the whole file is necessarily formatted incorrectly. If you did decide to throw a custom exception, it will still be the 'cause' of the FlatFileParseException, so I don't see why you would want to replace the much more informative message.
          1. It doesn't get to reading the third index because it fails at 2nd index (data type for the 2nd index is BigDecimal and here value provided is "0.22 2008-03-28".
          2. Instead of "File is not comma..." we can assume that the message would be "Record is not comma delimited....".
          3. There is a business requirement to assign an id based on the type of exception. For instance, if comma is missing or there is one less field for the record then exceptionId for this record would be 1111 or assign a message "Record has formatting issues.."

          Hoep that helps!

          Comment


          • #6
            So it seems like you could throw an InvalidRecordFormatException from your FieldSetMapper, and if you wanted to get to that from the FlatFileParseException it would just be parseException.getCause().

            Comment

            Working...
            X