Logging Exceptions within Classes

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Create a `System` class containing an `errors` list. The `run(cmd)` method raises a `RuntimeError(‘Execution Failed’)` if the command is ‘FAIL’. Catch it internally within the class, append the error message to `self.errors`, and print ‘Error Logged’. If successful, print ‘Running’.

Input Format

A single string command.

Output Format

Print the action, and if errors exist, print the first error in the list.

Constraints

None

Sample Input

FAIL

Sample Output

Error Logged
Execution Failed

Explanation

Classes often handle their own exceptions internally to log failures without crashing the overall application.

Starter Code

class System:
    def __init__(self):
        self.errors = []
    # Define run method with internal try-except

if __name__ == '__main__':
    cmd = input().strip()
    # Instantiate and run
    pass

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