Adding Custom Attributes to Exceptions

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Create a `ValidationError` exception that stores an integer `code` and a string `msg`. Read a code and message from input, raise the exception, catch it as `e`, and print ‘Code: [code], Msg: [msg]’.

Input Format

An integer and a string separated by a space.

Output Format

Print the formatted custom attributes.

Constraints

None

Sample Input

404 NotFound

Sample Output

Code: 404, Msg: NotFound

Explanation

Custom exceptions can carry additional state (like error codes) beyond just a basic string message.

Starter Code

class ValidationError(Exception):
    # Define __init__ to store code and msg
    pass

if __name__ == '__main__':
    data = input().split()
    # Raise and catch the exception
    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