The compiler knows which exceptions must be caught when a method is called because the method
specifies them in its signature.
Your methods can also throw exceptions - just add the throws
to your signature and list the Throwable class(es).
If your method lists any exceptions in the throws clause of the signature, your method code
does not need to catch the exception.
As a beginner, this (bad) technique lets you write code to prompt for input without handling exceptions:
public static void main (String args[]) throws IOException
{
BufferedReader keyboard =
new BufferedReader(new InputStreamReader(System.in));
...
}
If your method calls another method that throws one of the exceptions listed in the signature,
execution stops and the exception is thrown.
An exception is thrown up the call chain until it is caught (or your program crashes).
In other words, if the Exception isn't caught by code in your program, then it crashes.