위의 주어진 코드에 대한 솔루션은 다음과 같습니다.
예시
class CustomValueError(ValueError): def __init__(self, arg): self.arg = arg try: a = int(input("Enter a number:")) if not 1 < a < 10: raise CustomValueError("Value must be within 1 and 10.") except CustomValueError as e: print("CustomValueError Exception!", e.arg)
출력
Enter a number:45 CustomValueError Exception! Value must be within 1 and 10. Process finished with exit code 0