1.
try {
} finally {
}
Answer: Valid (A try block can have only a finally block without catch.)
2.
try {
} catch(Exception e) {
}
Answer: Valid (A try block can have only a catch block.)
3.
try {
} catch(Exception e) {
} finally {
}
Answer: Valid (A try block can have both catch and finally.)
4.
try {
} catch(ArithmeticException e) {
} catch(Exception e) {
}
**Answer:** Valid (Specific exception comes before general exception.)
5.
**Answer:** Not Valid (General exception must come after specific exception.)
try {
} catch(Exception e) {
} catch(ArithmeticException e) {
}
6.
try {
} finally {
} catch(Exception e) {
}
Answer: Not Valid (catch block must come before finally.)
7.
try {
} catch(ArithmeticException e) {
} finally {
} catch(Exception e) {
}
Answer: Not Valid (catch block cannot come after finally.)
8.
try {
} catch(Exception e) {
} finally {
} finally {
}
Answer: Not Valid (Only one finally block is allowed.)
9.
try {
}
Answer: Not Valid (try must be followed by at least one catch or a finally block.)
10.
catch(Exception e) {
}
Answer: Not Valid (catch cannot exist without a try block.)
11.
finally {
}
Answer: Not Valid (finally cannot exist without a try block.)
12.
try {
} catch(ArithmeticException e) {
} catch(ArithmeticException e) {
**Answer:** Not Valid (Duplicate catch blocks for the same exception are not allowed.)
}
13.
try {
} catch(Exception e) {
} catch(RuntimeException e) {
}
Answer: Not Valid (General exception must come after specific exception.)
14.
try {
} catch(RuntimeException e) {
} catch(Exception e) {
}
Answer: Valid (Specific exception comes before general exception.)
15.
try {
} finally {
} finally {
}
Answer: Not Valid (Only one finally block is allowed.)
Top comments (0)