184k views
1 vote
What is the difference between a try block and a try statement?

a. There is no difference; the terms can be used interchangeably.
b. A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.
c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.
d. The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.

1 Answer

3 votes

Final answer:

The term try block refers to just the 'try' keyword followed by potentially error-prone code, while the try statement includes the try block and any catch or finally clauses.

Step-by-step explanation:

The difference between a try block and a try statement is that a try block refers to just the keyword try followed by a block of code that is potentially prone to exceptions. In contrast, a try statement includes not only this block of code, but also the corresponding catch and/or finally clauses that handle any exceptions thrown by the try block. Therefore, the correct answer is option c: The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.

User KaliMa
by
8.8k points