One-line command to raise an Exception with a note?

  Kiến thức lập trình

I want this output:

RuntimeError: Unable to parse Powershell-encoded commands.
was a `{$...}` left in the command?

Process finished with exit code 1

I would like to use code like this:

if sys.argv[1] == '-encodedCommand':
    raise RuntimeError("Unable to parse Powershell-encoded commands.").with_note('was a `{$...}` left in the command?')

This code does what I want, but it looks ugly:

if sys.argv[1] == '-encodedCommand':
    to_raise =  RuntimeError(f"Unable to parse Powershell-encoded commands.")
    to_raise.add_note('was a `{$...}` left in the command?')
    raise to_raise

Does anyone have a suggestion?

New contributor

Daniel Lawson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT