Raising Exceptions in Property Setters

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Create a `Thermometer` class. Use the `@property` decorator for `temp`. In the `@temp.setter`, if the value is < -273, raise a `ValueError('Absolute Zero Violation')`. Handle the exception when trying to set an invalid temperature.

Input Format

A single integer.

Output Format

Print 'Set' if successful, or the error message if it fails.

Constraints

None

Sample Input

-300

Sample Output

Absolute Zero Violation

Explanation

Property setters act as gatekeepers, raising exceptions to protect the object from entering an invalid state after creation.

Starter Code

class Thermometer:
    def __init__(self):
        self._temp = 0
    # Add property and setter with exception logic

if __name__ == '__main__':
    val = int(input())
    # Apply the temperature and catch exceptions
    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