State Rollback on Error

Hard Exception Handling in OOP PRO
🔒 Login to Unlock

Problem Statement

Create an `Account` class initialized with a `balance`. The `withdraw(int amount)` method deducts the amount. If the new `balance` drops below 0, it MUST rollback the `balance` to the previous state and throw `std::runtime_error(“Insufficient Funds”)`. Read `init_bal` and `withdraw_amt`. Print ‘Success: [bal]’ or ‘[error_msg]: [rolled_back_bal]’.

Input Format

Two space-separated integers.

Output Format

Print the result and the protected balance.

Constraints

None

Sample Input

100 150

Sample Output

Insufficient Funds: 100

Explanation

Strong Exception Guarantee: If an operation fails, the object must cleanly rollback to the exact state it was in before the operation began.

Starter Code

#include <iostream>
#include <stdexcept>

class Account {
    // Implement balance, constructor, and rollback logic in withdraw()
};

int main() {
    // Read input and execute try-catch
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used