The golden rule is that any exceptions either declare them or handle them. The following is declaring and handling same exception. I thought that will cause compiler error. But it did NOT.
Java allows you to declare that you throw an exception even if you in fact don't throw it (as in this case). If your main() called m(), then main would have to either handle Exception or declare that it throws Exception.
Note that if you declare a checked exception, the compiler may complain if it can tell by inspection that there's no way that checked exception could have been thrown by the method. But unchecked exceptions could in theory be thrown by just about any code, so the compiler doesn't complain if you declare them. Declaring "throws Exception" (or "throws Throwable") is a special case; an Exception (or Throwable) could be either checked or unchecked, so the compiler assumes that since it could represent an unchecked exception, it's not going to complain if you declare the Exception, even if the compiler can't see how the exception might be thrown.
I don't think the compiler ever complains under those circumstances. It accepts this without complaint: class ExTest { void foo() throws java.sql.SQLException {} }
I agree with Ron. The compiler will not complain if method is only declaring that it might throw such and such exception and code is evidently not throwing anything. However, if there is a try region with code that is evidently not throwing anything, compiler will complain. Jim maybe that is what you were trying to express in your post. Thanks Barkat