Syntax

Python Raise an Exception Syntax

In Python, raise an exception: raises an error on purpose — raise ValueError("bad value")

Quick Answer

Syntax
raise ValueError("bad value")
PythonSyntax

Raise an Exception

Code example
raise ValueError("bad value")

Raises an error on purpose.

Learn More

How to raise an exception in Python

  1. Open your Python file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Python Raise an Exception Syntax

Use raise ValueError("bad value").

Related Syntax References

Frequently asked questions

What is the Python syntax for raise an exception?

Use this pattern: raise ValueError("bad value")

Can I copy this Python code example?

Yes. Use Copy code and adapt the example to your program.

Is this Python syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify