1.4. Use multi-catch in exception statements - Source Code

Code:

package c1.s4;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Mikalai Zaikin
 */
public class WriteToFile {
    private void correctWriting()  {
       try (DataOutputStream out = new DataOutputStream(new FileOutputStream("data"))) {
           out.writeInt(777);
           out.writeUTF("Hello");
       } catch (RuntimeException | IOException  e) {
           e = new Exception(); // COMPILATION ERROR: The 'e' can not be assigned
       }
   }
}
					

Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Free SCDJWS 5.0 Guide