Q1.
try {
} finally {
}
No compile error.
try should be followed either by catch or finally
Q2.
try {
} catch(Exception e) {
}
No compilation error.
try followed by catch
Q3.
try {
} catch(Exception e) {
} finally {
}
Answer: This is the right order:
if catch is present ,then it must be followed by try.1.try 2.catch 3.finally
4.try {
} catch(ArithmeticException e) {
} catch(Exception e) {
}
Ans: multiple catch allowed.
catch with Exception should be last of all other exceptions.
Q5.
try {
} catch(Exception e) {
} catch(ArithmeticException e) {
}
Answer: compile error.
Catch(Exception e) should be last .
Q6.
try {
} finally {
} catch(Exception e) {
}
Answer: compile error.
Catch() block cannot be after finally block
Q7.try {
} catch(Exception e) {
} finally {
} finally {
}
Ans: Multiple finally not allowed
Q8.
try {
} catch(ArithmeticException e) {
} finally {
} catch(Exception e) {
}
Answer: cath block is after finally block.compile error
Q9.try {
}
Ans: Compile error.
Either finally or catch block should follow
Q10.
catch(Exception e) {
}
Ans: catch block cannot be alone without try block
Q11.
11.
finally {
}
Ans: finally block cannot alone without try block
Q12.
try {
} catch(ArithmeticException e) {
} catch(ArithmeticException e) {
}
Ans: cannot have two catch blocks for the same exception type.
Q13.
try {
} catch(Exception e) {
} catch(RuntimeException e) {
}
Catch block with Exception should be last .
Q14.
try {
} catch(RuntimeException e) {
} catch(Exception e) {
}
Answer: Valid
15.
try {
} finally {
} finally {
}
Ans: Multiple finally block not allowed
Top comments (0)