019-005-006

Exception Handling: Finally Block Execution

Medium

Problem Description

exception handling: Finally Block Execution

In this problem, you will create a program that receives an integer input, handles division-by-zero exceptions using a try-catch-finally block, and displays the result to standard output.

Learning Objective: Understand that finally block always executes

Overview

The finally block is a code block that always executes, whether an exception occurs or not. It's used for resource cleanup and finalization.

Specifications

Create a program that receives an integer input and attempts division.

  • Output the result of 10 divided by the input value
  • If division by zero is attempted, output an error message
  • In both cases, output "Cleanup completed" at the end

Input Format

<integer value>

Output Format

On success:

Result: <result>
Cleanup completed

On failure:

Error: Cannot divide by zero
Cleanup completed

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up