Oracle
1Z0-805 · Question #88
Given: import java.io.*; public class SampleClass { public static void main(String[] args) throws IOException { try { String dirName = args[0]; File dir = new File(dirName)…
The correct answer is A. Compilation fails. The multi-catch parameter e may not be assigned. The compilation will fail at line: e = new IOException("Error while creating temp file");
Exceptions and Assertions
Question
Given:
import java.io.*; public class SampleClass { public static void main(String[] args) throws IOException { try { String dirName = args[0]; File dir = new File(dirName); File.createTempFile("temp", "log", dir); } catch (NullPointerException | IOException e) { e = new IOException("Error while creating temp file"); throw e; } } } What is the result?
Options
- ACompilation fails.
- BAn IOException with the default message is thrown at runtime.
- CAn IOException with the message Error while creating temp file is thrown at runtime.
- DA temporary file is created in the specified directory.
How the community answered
(53 responses)- A77% (41)
- B15% (8)
- C2% (1)
- D6% (3)
Explanation
The multi-catch parameter e may not be assigned. The compilation will fail at line: e = new IOException("Error while creating temp file");
Topics
#multi-catch#exception reassignment#effectively final#IOException
Community Discussion
No community discussion yet for this question.