Best Practices for Python Exceptions?

后端 未结 5 832
北恋
北恋 2021-01-29 20:04

What are the best practices for creating exceptions? I just saw this, and I don\'t know if I should be horrified, or like it. I read several times in books that exceptions shoul

5条回答
  •  遇见更好的自我
    2021-01-29 20:48

    class Error(Exception):
        """Base class for other exceptions"""
        pass
    
    class empty_string_error(Error):
        """Raised when the input value is too large"""
        pass
    while(1):
        try:
            if("Your Condition"):
                raise empty_string_error
            else:
                print("OUTPUT")
        except empty_string_error:
            print("APT MESSAGE")
            print(" ")
        finally:
            pint("Mandatory code")
    

提交回复
热议问题