[CSV] Throw custom runtime exception from iterator.next()?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[CSV] Throw custom runtime exception from iterator.next()?

Benedikt Ritter-4
Hi,

in our iterator implementation returned by CSVParser.iterator() we wrap
IOExceptions into RuntimeExceptions because we cannot throw IOException
from the iterator methods. For this reason, user code has to catch
RuntimeException in order to recover from parsing failures.
I was thinking whether it would be better to define a custom
RuntimeException, say CSVParsingException extends RuntimeException so user
code can only react to this kind of failures.

WDYT?

Benedikt
Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

jochen-2
On Tue, Oct 25, 2016 at 11:30 AM, Benedikt Ritter <[hidden email]> wrote:

> in our iterator implementation returned by CSVParser.iterator() we wrap
> IOExceptions into RuntimeExceptions because we cannot throw IOException
> from the iterator methods. For this reason, user code has to catch
> RuntimeException in order to recover from parsing failures.
> I was thinking whether it would be better to define a custom
> RuntimeException, say CSVParsingException extends RuntimeException so user
> code can only react to this kind of failures.

Please, do that.

Jochen

--
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

garydgregory
In reply to this post by Benedikt Ritter-4
Or IllegalStateExecption?

Gary

On Oct 25, 2016 2:31 AM, "Benedikt Ritter" <[hidden email]> wrote:

> Hi,
>
> in our iterator implementation returned by CSVParser.iterator() we wrap
> IOExceptions into RuntimeExceptions because we cannot throw IOException
> from the iterator methods. For this reason, user code has to catch
> RuntimeException in order to recover from parsing failures.
> I was thinking whether it would be better to define a custom
> RuntimeException, say CSVParsingException extends RuntimeException so user
> code can only react to this kind of failures.
>
> WDYT?
>
> Benedikt
>
Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

jochen-2
On Tue, Oct 25, 2016 at 4:45 PM, Gary Gregory <[hidden email]> wrote:
> Or IllegalStateExecption?

Bit generic, and not to be used inflationary. I'd clearly prefer a
custom RuntimeException, as suggested by Benedikt.

> On Oct 25, 2016 2:31 AM, "Benedikt Ritter" <[hidden email]> wrote:
>
>> Hi,
>>
>> in our iterator implementation returned by CSVParser.iterator() we wrap
>> IOExceptions into RuntimeExceptions because we cannot throw IOException
>> from the iterator methods. For this reason, user code has to catch
>> RuntimeException in order to recover from parsing failures.
>> I was thinking whether it would be better to define a custom
>> RuntimeException, say CSVParsingException extends RuntimeException so user
>> code can only react to this kind of failures.
>>
>> WDYT?
>>
>> Benedikt
>>



--
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

Emmanuel Bourg-3
In reply to this post by Benedikt Ritter-4
Le 25/10/2016 à 11:30, Benedikt Ritter a écrit :

> WDYT?

Good idea.

Emmanuel Bourg


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

garydgregory
In reply to this post by jochen-2
Using RE is a no-no, so we need to do _something_

The code already suggests using an ISE:

                    // TODO: This is not great, throw an ISE instead?
                    throw new RuntimeException(e);

Curious: Why is adding a custom exception better that ISE? The question
will then be "Why do we not throw the custom exception all over instead of
JRE exceptions?"

Gary

On Tue, Oct 25, 2016 at 7:56 AM, Jochen Wiedmann <[hidden email]>
wrote:

> On Tue, Oct 25, 2016 at 4:45 PM, Gary Gregory <[hidden email]>
> wrote:
> > Or IllegalStateExecption?
>
> Bit generic, and not to be used inflationary. I'd clearly prefer a
> custom RuntimeException, as suggested by Benedikt.
>
> > On Oct 25, 2016 2:31 AM, "Benedikt Ritter" <[hidden email]> wrote:
> >
> >> Hi,
> >>
> >> in our iterator implementation returned by CSVParser.iterator() we wrap
> >> IOExceptions into RuntimeExceptions because we cannot throw IOException
> >> from the iterator methods. For this reason, user code has to catch
> >> RuntimeException in order to recover from parsing failures.
> >> I was thinking whether it would be better to define a custom
> >> RuntimeException, say CSVParsingException extends RuntimeException so
> user
> >> code can only react to this kind of failures.
> >>
> >> WDYT?
> >>
> >> Benedikt
> >>
>
>
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/
> evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

Gilles Sadowski
On Tue, 25 Oct 2016 10:37:13 -0700, Gary Gregory wrote:

> Using RE is a no-no, so we need to do _something_
>
> The code already suggests using an ISE:
>
>                     // TODO: This is not great, throw an ISE instead?
>                     throw new RuntimeException(e);
>
> Curious: Why is adding a custom exception better that ISE? The
> question
> will then be "Why do we not throw the custom exception all over
> instead of
> JRE exceptions?"

public class CSVParsingException extends IllegalStateException { /* ...
*/ }

Gilles


> Gary
>
> On Tue, Oct 25, 2016 at 7:56 AM, Jochen Wiedmann
> <[hidden email]>
> wrote:
>
>> On Tue, Oct 25, 2016 at 4:45 PM, Gary Gregory
>> <[hidden email]>
>> wrote:
>> > Or IllegalStateExecption?
>>
>> Bit generic, and not to be used inflationary. I'd clearly prefer a
>> custom RuntimeException, as suggested by Benedikt.
>>
>> > On Oct 25, 2016 2:31 AM, "Benedikt Ritter" <[hidden email]>
>> wrote:
>> >
>> >> Hi,
>> >>
>> >> in our iterator implementation returned by CSVParser.iterator()
>> we wrap
>> >> IOExceptions into RuntimeExceptions because we cannot throw
>> IOException
>> >> from the iterator methods. For this reason, user code has to
>> catch
>> >> RuntimeException in order to recover from parsing failures.
>> >> I was thinking whether it would be better to define a custom
>> >> RuntimeException, say CSVParsingException extends
>> RuntimeException so
>> user
>> >> code can only react to this kind of failures.
>> >>
>> >> WDYT?
>> >>
>> >> Benedikt
>> >>
>>
>>
>>
>> --
>> The next time you hear: "Don't reinvent the wheel!"
>>
>> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/
>> evolution-of-the-wheel-300x85.jpg
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> --
> E-Mail: [hidden email] | [hidden email]
> Java Persistence with Hibernate, Second Edition
>
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
>
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
>
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [CSV] Throw custom runtime exception from iterator.next()?

garydgregory
Tracking here: https://issues.apache.org/jira/browse/CSV-201

Gary

On Tue, Oct 25, 2016 at 10:45 AM, Gilles <[hidden email]>
wrote:

> On Tue, 25 Oct 2016 10:37:13 -0700, Gary Gregory wrote:
>
>> Using RE is a no-no, so we need to do _something_
>>
>> The code already suggests using an ISE:
>>
>>                     // TODO: This is not great, throw an ISE instead?
>>                     throw new RuntimeException(e);
>>
>> Curious: Why is adding a custom exception better that ISE? The question
>> will then be "Why do we not throw the custom exception all over instead of
>> JRE exceptions?"
>>
>
> public class CSVParsingException extends IllegalStateException { /* ... */
> }
>
> Gilles
>
>
> Gary
>>
>> On Tue, Oct 25, 2016 at 7:56 AM, Jochen Wiedmann <
>> [hidden email]>
>> wrote:
>>
>> On Tue, Oct 25, 2016 at 4:45 PM, Gary Gregory <[hidden email]>
>>> wrote:
>>> > Or IllegalStateExecption?
>>>
>>> Bit generic, and not to be used inflationary. I'd clearly prefer a
>>> custom RuntimeException, as suggested by Benedikt.
>>>
>>> > On Oct 25, 2016 2:31 AM, "Benedikt Ritter" <[hidden email]> wrote:
>>> >
>>> >> Hi,
>>> >>
>>> >> in our iterator implementation returned by CSVParser.iterator() we
>>> wrap
>>> >> IOExceptions into RuntimeExceptions because we cannot throw
>>> IOException
>>> >> from the iterator methods. For this reason, user code has to catch
>>> >> RuntimeException in order to recover from parsing failures.
>>> >> I was thinking whether it would be better to define a custom
>>> >> RuntimeException, say CSVParsingException extends RuntimeException so
>>> user
>>> >> code can only react to this kind of failures.
>>> >>
>>> >> WDYT?
>>> >>
>>> >> Benedikt
>>> >>
>>>
>>>
>>>
>>> --
>>> The next time you hear: "Don't reinvent the wheel!"
>>>
>>> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/
>>> evolution-of-the-wheel-300x85.jpg
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>
>> --
>> E-Mail: [hidden email] | [hidden email]
>> Java Persistence with Hibernate, Second Edition
>>
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
>> Code=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1617290459>
>> JUnit in Action, Second Edition
>>
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
>> Code=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182021>
>> Spring Batch in Action
>>
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
>> Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
>> nk_id%7D%7D%22%3ESpring+Batch+in+Action>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory