Python program to raise an exception
belongs to collection: Python Exception Handling Programs
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
belongs to collection: Python Exception Handling Programs
total answers (1)
To throw an exception on a particular condition – we use the "raise" keyword.
In the below examples, we have two files:
In the program, we will read marks and check whether entered value is between 0 and 100 or not, if the value is other than the range, we are throwing an error using the "raise" keyword.
MyLib.py:
Main.py:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer