Designing a Custom Exception Hierarchy

Hard Exception Handling in OOP PRO
🔒 Login to Unlock

Problem Statement

Create a base `AppError(Exception)`. Create two subclasses: `DatabaseError(AppError)` and `NetworkError(AppError)`. If the input is ‘DB’, raise `DatabaseError`. If ‘NET’, raise `NetworkError`. Catch them purely using the base `AppError` and print ‘AppError caught: [name of class]’.

Input Format

A single string ('DB' or 'NET').

Output Format

Print the caught base exception.

Constraints

None

Sample Input

DB

Sample Output

AppError caught: DatabaseError

Explanation

A structured hierarchy allows you to catch broad categories of exceptions (AppError) while still retaining specific sub-type information.

Starter Code

class AppError(Exception): pass
# Define DatabaseError and NetworkError

if __name__ == '__main__':
    err_type = input().strip()
    # Raise specific error, catch with AppError
    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