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

前端 未结 12 1121
情书的邮戳
情书的邮戳 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 09:58

    This code template should allow you to raise an exception with a custom message.

    try:
         raise ValueError
    except ValueError as err:
        raise type(err)("my message")
    

提交回复
热议问题