Loading ...
Sorry, an error occurred while loading the content.

Re: VS: [XP] Test Driven Exceptions

Expand Messages
  • J. B. Rainsberger
    ... Robert Watkins pointed that out, too. As a wrote to him, since I must return something, and int doesn t allow me to return a value representing
    Message 1 of 15 , Jun 4, 2004
    • 0 Attachment
      lasse.koskela@... wrote:
      > JB:
      >
      >>...or...
      >>
      >>| public int toInt(String s) {
      >>| try {
      >>| return Integer.parseInt(s);
      >>| } catch (NumberFormatException ignored) {
      >>| }
      >>| }
      >
      > ...except that this won't compile ;)

      Robert Watkins pointed that out, too. As a wrote to him, since I must
      return something, and "int" doesn't allow me to return a value
      representing "nothing," the method signature is inadequate to the
      current task. Either I have to change it or add extra stuff to mollify
      the compiler.

      >
      > JB:
      >>(By the way... NumberFormatException is unchecked, so I don't even have
      >>to catch it!)
      >
      > Wow. So it seems. I picked a bad example after all.
      > I'm so used to "expect" a NumberFormatException that I've subconsciously made it a "checked" exception :)

      Someone else suggested catching NFE and throwing
      IllegalArgumentException, so I checked it out: NFE /is/ an IAE. :)
      (Makes sense from the names, no?)
      --
      J. B. Rainsberger,
      Diaspar Software Services
      http://www.diasparsoftware.com :: +1 416 791-8603
      Let's write software that people understand
    Your message has been successfully submitted and would be delivered to recipients shortly.