Designing Custom Exception Classes

Easy Exception Handling in OOP
Solve in Playground →

Problem Statement

Define an empty custom exception class `InvalidAgeError` that inherits from Python’s base `Exception`. Read an integer age. If age is less than 0, raise `InvalidAgeError`. Catch it and print ‘InvalidAgeError caught’, otherwise print ‘Valid’.

Input Format

A single integer.

Output Format

Print the validation status.

Constraints

None

Sample Input

-5

Sample Output

InvalidAgeError caught

Explanation

Custom exceptions are created by simply inheriting from the built-in Exception class.

Starter Code

# Define InvalidAgeError here

if __name__ == '__main__':
    age = int(input())
    # Write try-except block here
    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