<<< Java Exception Class | Index | Checked exceptions >>> |
Each Java program must follow this rule: the code will not compile unless the Catch or Specify requirement is honored. When 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 (catch)
try { //a block of code that can throw an exception } catch ( ExceptionType ex ) { //... }
(b) enclosed in a method with the throws clause (specify)
public void saveFile() throws IOException {
//a block of code that can throw an exception
}///saveFile
<<< Java Exception Class | Index | Checked exceptions >>> |