Programmers partition application logic that may throw exceptions into a try block, followed by a catch block to handle these exceptions. An optional finally block, if present, is executed, regardless of whether an exception is thrown by a try block. You cannot just have a try block—it has to be accompanied by either a catch block or a finally block.
In this section, we will look at different code blocks in order to understand the usage of the try-catch statement, the try-finally statement, and the try-catch-finally statement.
You can use a try-catch statement without a finally block like so:
try{ //code block which might trigger exceptions}catch (SpecificException ex){ //exception handling code block }
The system also ...