I'm not sure I understand your question, but I will take a hit on him. The compiler is trying to help you avoid errors. If you had code in a try block that throws a SQLException, but your catch block had a typo and you caught a SLQException, then you would like the compiler to flag this error. Therefore, he puts it as an error, the exception you catch is never thrown.
I think the second part of your question is: why can you put whatever you want into the throws clause of your method declaration, regardless of whether the method actually throws this exception? I think there are two reasons. First, a method declaration is an interface and tells clients how to code it. You can customize the method declaration and make it available to your employees before filling out the method body. Therefore, in this case, this is not a mistake, but only incomplete work. Secondly, your class can implement an interface that declares a method as an exception, but in your specific implementation you do not need to throw it. Again, this is not a mistake.
source share