How do I raise the same Exception with a custom message in Python?

前端 未结 12 1132
情书的邮戳
情书的邮戳 2020-12-12 09:45

I have this try block in my code:

try:
    do_something_that_might_raise_an_exception()
except ValueError as err:
    errmsg = \'My custom error         


        
12条回答
  •  悲&欢浪女
    2020-12-12 10:15

    if you want to custom the error type, a simple thing you can do is to define an error class based on ValueError.

提交回复
热议问题