Question 1
It is recommended that you should not use return, break, continue or throw statements in _________
- AOption A:
Finally block
- BOption B:
Try-With-Resources block
- COption C:
Try block
- DOption D:
Catch block
Show answer and explanation
Correct answer: A
The finally block is used to execute important code such as closing resources, regardless of whether an exception was thrown or handled. Using control transfer statements like return , break , continue , or throw in a finally block can disrupt the normal flow of execution and can lead to unexpected behavior or resource leaks, as these statements may cause the method to exit before the resources are properly closed.
References: The guidelines and best practices for Java application security, as outlined by the EC-Council’s Certified Application Security Engineer (CASE) program, emphasize the importance of proper resource management and error handling in secure application development. The CASE program provides comprehensive training on secure coding practices, which includes managing the flow of execution to ensure that resources are properly released and that applications are robust against exceptions and errors.