Discussion
Which line contains the error?
public class Sample68
{
static int count()
{
try
{
assert false : "unreachable";
return 1;
}
finally
{
return 2;
}
}
public static void main(String[] args)
{
System.out.println(count());
}
}
Answer: D
A return inside finally discards whatever the try was doing, including a thrown AssertionError, so the method quietly returns 2 and the failed assertion vanishes. Returning from finally swallows errors and should never be done; the assertion is only the victim here.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development