Machine-translated by Google. Questions are authored in English.
Top

Discussion

In exception handling, which block is executed regardless of whether an exception occurs ?

  • A.try
  • B.catch
  • C.finally
  • D.throw

Answer: C

The block is finally.

In languages such as Java, C# and Python, a finally block after try/catch runs whether the try block completes normally, throws an exception that is caught, or throws one that is not caught. It is used for cleanup, such as closing files and releasing locks.

The try block holds the code that may fail, and it stops at the first exception. A catch block runs only when a matching exception is thrown. throw is a statement that raises an exception, not a block that always runs.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.