Forum Stats

  • 3,837,101 Users
  • 2,262,226 Discussions
  • 7,900,203 Comments

Discussions

Unchecked exceptions thrown by parsers

yecril15pl
yecril15pl Member Posts: 4 Red Ribbon
edited Jun 29, 2018 7:20PM in Java Programming

Why are exceptions thrown by parsers, such as parseInt, unchecked?  It is not a programming error to try to parse text input containing errors or optional values that need not be present.

Answers

  • Unknown
    edited Jun 29, 2018 7:20PM
    Why are exceptions thrown by parsers, such as parseInt, unchecked? It is not a programming error to try to parse text input containing errors or optional values that need not be present. 

    Same answer as in your other thread - only the person designing the code can answer 'why' questions about the choices they made.

    (note - my using the 'only the developer ...' is NOT meant to discourage you from posting such questions - only trying to be inform you/others that it is a design decision and, as such, only the developer knows the real reason that decision was made).

    An earlier doc section states this:

    The third kind of exception is the runtime exception. These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from.

    And further classifies those as 'unchecked'.

    Certainly the argument can be made that a problem parsing something can both be anticipated and recovered from so should raise a checked exception.

    Although different people might argue differently in the forums ONLY the developer can tell you why any given choice was made. There could have been a legitimate reason or it could have been ignorance of best practices in writing exceptions and handlers as your other doc link discusses.

This discussion has been closed.