catch analysis is too strict (ignores unchecked classes)

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 8
    • Affects Version/s: 8
    • Component/s: specification
    • None
    • generic
    • generic
    • Verified

      JLS7 11.2.3 makes an analysis of catch blocks: "It is a compile-time error if a catch clause can catch (§11.2) checked exception class E1 and a preceding catch block of the immediately enclosing try statement can catch E1 or a superclass of E1."

      There is no reason to restrict the analysis to checked exception classes. The desired principle is that the first catch of exception class E preempts later catches of E and subclasses of E. (Because that's the runtime behavior.) The word "checked" should be changed to "an".

      Note that the preceding 11.2.3 rule - where a catch of a checked exception class is compared to a try block - is OK. It's not possible to prove an error if all you have is one catch of an _unchecked_ exception class and a try block; you must look at _other catch clauses_ to prove an error (namely, redundancy due to preemption).

      Finally, 11.2 should say "We say that a statement or expression can throw ***an exception*** class E..." rather than "a checked exception class E". Whether a class is a checked exception class or an unchecked exception class is irrelevant for some rules in 11.2.3, and those rules that care will restrict themselves to checked exception classes.

            Assignee:
            Alex Buckley
            Reporter:
            Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: