2.9.1.3 Custom Exceptions
Python Programming
Custom exceptions allow you to define your own error types that can be raised and handled specifically.
python
class CustomError(Exception):
pass # pass statement is a placeholder that does nothing when executed
def check_value(value):
if value < 0:
raise CustomError("Value must be non-negative ! " )
try :
check_value(-1)
except CustomError as e:
print("Error :" , e)