Code Issues – Try statement without catch or finally
This code issue shows an error if a ‘try’ statement doesn’t have a ‘catch’ or ‘finally’ statement. The try block must be completed, whether with catch or finally blocks.
The try block contains the guarded code that may cause the exception. The block is executed until an exception is thrown or it is completed successfully.
The catch block is used to take a control when any or a specific exception has been thrown.
The finally block is useful for cleaning up any resources allocated in the try block, as well as running any code that must execute even if there is an exception. Control is always passed to the finally block regardless of how the try block exits.
How to fix:
- Add the missing catch block:
- Add the missing finally block:
- Add the missing catch and finally blocks:
—– Products: CodeRush Pro Versions: 12.1 and up VS IDEs: any Updated: Nov/19/2012 ID: C057