RFR: Do not catch NoSuchElementException in HgOpenJDKImport
Erik Duveblad via github.com
duke at openjdk.java.net
Thu Aug 22 14:45:47 UTC 2019
On Thu, 22 Aug 2019 14:29:37 GMT, Robin Westberg via github.com <duke at openjdk.java.net> wrote:
> On Thu, 22 Aug 2019 14:16:17 GMT, Erik Duveblad via github.com <duke at openjdk.java.net> wrote:
>
>> Hi all,
>>
>> this patch removes catching `NoSuchElementException` in the `main` method for `HgOpenJDKImport` to ease debugging.
>>
>> ## Testing
>> - [x] `sh gradlew test` passes on Linux x86_64
>>
>> Thanks,
>> Erik
>>
>> ----------------
>>
>> Commits:
>> - 5536e051: Do not catch NoSuchElementException in HgOpenJDKImport
>>
>> Pull request:
>> https://git.openjdk.java.net/skara/pull/70
>>
>> Webrev:
>> https://webrevs.openjdk.java.net/skara/70/webrev.00
>>
>> Patch:
>> https://git.openjdk.java.net/skara/pull/70.diff
>>
>> Fetch command:
>> git fetch https://git.openjdk.java.net/skara pull/70/head:pull/70
>
> cli/src/main/java/org/openjdk/skara/cli/HgOpenJDKImport.java line 44:
>
>> 43: public static void main(String[] args) throws IOException, NoSuchElementException {
>> 44: var flags = List.of(
>> 45: Switch.shortcut("")
>
> Pre-existing, but it's a bit unclear why NoSuchElementException is used - plain RuntimeException (or Exception) would probably make more sense? Or perhaps something like NoSuchFileException?
>
> PR: https://git.openjdk.java.net/skara/pull/70
Yes, that is a bit unclear to me as well, and I even wrote the code in the first place :laughing: I _think_ I wanted my `catch` clause to catch `NoSuchElementException` so I could just do `.orElseThrow()` or `.get()` and still display a somewhat nice error message automatically. Pretty bad idea in retrospect, I will rework this.
PR: https://git.openjdk.java.net/skara/pull/70
Yes, you are totally right, thanks!
PR: https://git.openjdk.java.net/skara/pull/70
More information about the skara-dev
mailing list