[ 
https://issues.apache.org/jira/browse/GEOMETRY-138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17386994#comment-17386994
 ] 

Matt Juntunen commented on GEOMETRY-138:
----------------------------------------

Sounds good. Based on what I'm reading here, we could just do the following:
- Wrap all {{IOException}}s with {{UncheckedIOException}}s.
- Replace all other thrown exceptions with either {{IllegalArgumentException}} 
or {{IllegalStateException}}, depending on what the particular case calls for. 
It sounds like you consider IAE as the best match for parsing and syntax 
errors, since the input data can be considered a kind of argument. Is this 
correct?

Before I implement this,  I have a couple more questions.

1. How should like be documented? Documenting checked exceptions is easy since 
the exceptions are part of the method signature. Documenting possible unchecked 
exceptions is harder, especially for high-level methods, since the possible 
exceptions types and causes can be large. For the geometry read methods, the 
general rule will be that an {{UncheckedIOException}} means an IO error and any 
other {{RuntimeException}} (e.g. IAE or ISE) means a parsing or mathematical 
error. Is it appropriate to document this as such? Ex:
{code:java}
/**
 * ...
 * @throws RuntimeException if the input data is syntactically or 
mathematically invalid
 * @throws UncheckedIOException if an I/O error occurs
 */
BoundarySource3D read(...) { ... }
{code}
The above feels incorrect to me but adding more detail seems excessive, prone 
to error, and difficult to maintain.

2. If a user of the library needs to take some action on any and all errors 
from an IO operation, they will necessarily need to catch either 
{{RuntimeException}} or {{Exception}}. Those are the only options for ensuring 
that typical library failures do not propagate. However, catching general 
exceptions like this is typically viewed as a code smell and something to 
avoid. Is there a way to prevent this? (This is more of a general question than 
something specific to commons-geometry.)

> Use unchecked exceptions in IO modules
> --------------------------------------
>
>                 Key: GEOMETRY-138
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-138
>             Project: Apache Commons Geometry
>          Issue Type: Improvement
>            Reporter: Matt Juntunen
>            Priority: Major
>
> The IO modules should not throw checked exceptions, e.g. {{IOException}}. 
> Instead, a new unchecked {{GeometryIOException}} class should be created to 
> represent all IO and parsing failures.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to