Is it possible to tell the compiler that a method always throws an Exception
<p>Generally speaking, the Java compiler does not propagate the information that a method "always" throw an Exception, and therefore, does not detect that all code paths are complete.</p>

<p>(This is due to the fact that Java compiler compiles each class independently).</p>

<p>It's a problem when you want to write something like that.</p>

<pre><code>public class ErrorContext {
    public void fatalISE(String message) {
        String context = "gather lots of information about the context of the error";
        throw new IllegalStateException(context +": " + message);
    }
}

public class A {
    public MyObject myMethod() {
        if (allIsGood()) {
            return new MyObject();
        }
        ErrorContext.fatalISE("all is not good");
    }
}
</code></pre>

<p>(ie, a kind of "assertion helper" that gathers context information).</p>

<p>Because the compiler will complain that myMethod does not always return a MyObject.</p>

<p>To my knowledge, there is no specific annotation to indicate that a method always throws.</p>
