Advertisement
elena1234

Custom Error in Python

Feb 9th, 2022
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. class ValueCannotbeNegativeOrZeroError(Exception):
  2.     pass
  3.  
  4. def validate_numbers(numbers):
  5.     for num in numbers:
  6.         if num <= 0:
  7.             raise ValueCannotbeNegativeOrZeroError("Please, enter only positive numbers!")
  8.        
  9. numbers = [1, 2, 3, 4, 0]
  10.  
  11. validate_numbers(numbers)
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement