Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is the purpose of the 'try', 'catch', and 'finally' blocks in exception handling?
Answer: 'try' is used to enclose a block of code that might raise an exception. 'catch' is used to handle the exception, and 'finally' is used for code that must be executed regardless of whether an exception was thrown or not.

Example:

Ensuring resources are released in the 'finally' block, even if an exception occurs.
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook