019-007-004
Transaction: Rollback Handling on Exception
Hard
Problem Description
Transaction: Rollback Handling on Exception
In this problem, you will create a program that implements a TransactionManager class to execute multiple operations as a single transaction, rolls back the value to 0 if a failure operation occurs, and displays the result to standard output.
Learning Objective: Understand how to rollback transactions on exception to maintain consistency
Input
Line 1: Number of operations
Following: Each operation ("add [value]" or "fail")
Output
Operation log:Executing: [operation]
On success: Committed. Final value: [value]
On failure: Rollback. Value restored: 0
Example
Input:
3
add 10
add 20
add 5
Output:
Executing: add 10
Executing: add 20
Executing: add 5
Committed. Final value: 35
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