How to raise my exceptions instead of built-in exceptions?
问题 In some cases, I need to raise my exception because built-in exceptions are not fit to my programs. After I defined my exception, python raises both my exception and built-in exception, how to handle this situation? I want to only print mine? class MyExceptions(ValueError): """Custom exception.""" pass try: int(age) except ValueError: raise MyExceptions('age should be an integer, not str.') The output: Traceback (most recent call last): File "new.py", line 10, in <module> int(age) ValueError: