<<< Another Scanner hasNextDouble example | Index | >>> |
Each Java program must follow this rule:
if a block of code can throw an exception, such block of code must be
(a) wrapped by a try statement that catches exceptions and handles them in the corresponding catch blocks.
try { //a block of code that can throw an exception } catch (ExceptionType name) { }
(b) enclosed in a method with the throws clause, for example,
public void saveFile() throws IOException {
//a block of code that can throw an exception
}///saveFile
Otherwise, if Catch or Specify requirement is not honored, the code will not compile.
<<< Another Scanner hasNextDouble example | Index | >>> |