DISQUS

Andy Palmer: Checked Exceptions are Waste

  • Rugbyhead · 1 year ago
    Liking the ExceptionHandler object idea, could prove to be very versatile and flexible...
    Next workshop?? :D
  • Steve Freeman · 1 year ago
    The reason Java checked exceptions are a pain is because, like everything in Java, they didn't quite finish when they adopted the idea. In Modula-3, there is a FATAL pragma which meant that you can declare that you don't know how to handle a checked exception within a given scope. If such an exception occurs then the program fails. It's so simple but it makes all the difference to the usability of checked exceptions.

    The point of checked exceptions is that it allows me to know all the paths out of a chunk of code, otherwise I have to assume that any method call can fail and over-protect the logic.
  • Kevin Wong · 3 months ago
    I always change my Eclipse default catch clause to:
    throw new RuntimeException(e);

    Don't add and exception to the throws clause unless it will make sense to the caller. If it's a case that should never happen, or cannot be handled, wrap it in a RuntimeException, which effectively converts the checked exception to an unchecked one.

    I don't see why an "ignores" clause couldn't be added to Java methods to do this wrapping automatically.