It has two purposes.

jackcogdill has given the first one:

It's used for raising your own errors.

if something:
   raise Exception('My error!')

The second is to reraise the current exception in an exception handler, so that it can be handled further up the call stack.

try:
  generate_exception()
except SomeException as e:
  if not can_handle(e):
    raise
  handle_exception(e)
Answer from Ignacio Vazquez-Abrams on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_keyword_raise.asp
Python raise Keyword
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The raise keyword is used to raise an exception. You can define what kind of error to raise, and the text to print to the user. ... If you want to use W3Schools ...
🌐
W3Schools
w3schools.com › python › gloss_python_raise.asp
Python Raise an Exception
Python Examples Python Compiler ... to throw an exception if a condition occurs. To throw (or raise) an exception, use the raise keyword....
🌐
W3Schools
w3schools.com › python › python_try_except.asp
Python Try Except
Raise an error and stop the program if x is lower than 0: x = -1 if x < 0: raise Exception("Sorry, no numbers below zero") Try it Yourself » · The raise keyword is used to raise an exception.
🌐
W3Schools
w3schools.com › python › python_examples.asp
Python Examples
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
W3Schools
w3schools.in › python › exception-handling
Python Exceptions Handling - W3Schools
try/except: catch the error and recover from exceptions hoist by programmers or Python itself. try/finally: Whether exception occurs or not, it automatically performs the clean-up action. assert: triggers an exception conditionally in the code. raise: manually triggers an exception in the code.
🌐
W3Schools
w3schools.com › python › python_getstarted.asp
Python Getting Started
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... At W3Schools, you can try Python without installing anything.
🌐
Google Translate
translate.google.com › translate
Python Raise an Exception
As a Python developer you can choose to throw an exception if a condition occurs. To throw (or raise) an exception, use the raise keyword. Raise an error and stop the program if x is lower than 0: x = -1 if x < 0: raise Exception("Sorry, no numbers below zero") Try it Yourself » · The raise keyword is used to raise an exception. You can define what kind of error to raise, and the text to print to the user. ... If you want to use W3Schools ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › default.asp
Python Tutorial - W3Schools
This tutorial supplements all explanations with clarifying examples. ... Test your Python skills with a quiz. ... This is an optional feature. You can study at W3Schools without creating an account.
🌐
w3resource
w3resource.com › python › python-raise-exceptions-with-examples.php
Python Raising Exceptions: Learn How and When to Raise Errors
August 26, 2024 - In this example, the 'divide_numbers' function checks if the denominator is zero before performing division. If it is, a 'ZeroDivisionError' is raised, preventing the division and signaling the error.
🌐
W3Schools
w3schools.com › python
Python Tutorial
This tutorial supplements all explanations with clarifying examples. ... Test your Python skills with a quiz. ... This is an optional feature. You can study at W3Schools without creating an account.
🌐
W3Schools
w3schools.com › python › python_syntax.asp
Python Syntax
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-raise-keyword
Python Raise Keyword - GeeksforGeeks
July 23, 2025 - In the below code, we tried changing the string 'apple' assigned to s to integer and wrote a try-except clause to raise the ValueError.
🌐
W3Schools
w3schools.com › python › python_intro.asp
Introduction to Python
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 14-5-raising-exceptions
14.5 Raising exceptions - Introduction to Python Programming | OpenStax
March 13, 2024 - The following class represents a pizza for sale. The SIZES dictionary maps an abbreviation to a size's name and price. Line 11 checks if the size received by the constructor is in the dictionary.
🌐
W3Schools
w3schools.com › python › ref_keyword_assert.asp
Python assert Keyword
Python Examples Python Compiler ... condition returns True, then nothing happens: assert x == "hello" #if condition returns False, AssertionError is raised: assert x == "goodbye" Try it Yourself »...
🌐
W3Schools
w3schools.com › python › gloss_python_error_handling.asp
Python Error Handling
When an error occurs, or exception as we call it, Python will normally stop and generate an error message. These exceptions can be handled using the try statement: The try block will generate an exception, because x is not defined: try: print(x) except: print("An exception occurred") Try it Yourself » · Since the try block raises an error, the except block will be executed.
🌐
W3Schools
w3schools.com › python › gloss_python_iterator_stop.asp
Python Stop Iteration
class MyNumbers: def __iter__(self): self.a = 1 return self def __next__(self): if self.a <= 20: x = self.a self.a += 1 return x else: raise StopIteration myclass = MyNumbers() myiter = iter(myclass) for x in myiter: print(x) Try it Yourself » · Python Iterator Tutorial Iterators Iterator vs Iterable Loop Through an Iterator Create an Iterator ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
APXML
apxml.com › courses › python-for-beginners › chapter-9-handling-errors-exceptions › python-raising-exceptions
Raising Python Exceptions | `raise` Statement
Here, ExceptionType is the class ... want to raise. Python has many built-in exception types suitable for various error conditions. It's generally good practice to use the most specific, appropriate built-in exception type available. The optional string argument provides a human-readable message explaining the cause of the error, which is very helpful for debugging. Let's look at an example...
🌐
GeeksforGeeks
geeksforgeeks.org › python › user-defined-exceptions-python-examples
User-defined Exceptions in Python with Examples - GeeksforGeeks
February 12, 2026 - In set_age(), if the age is outside the valid range (0–120), the exception is raised. The try-except block catches the exception and prints the error message. When we create a custom exception, we subclass Python’s built-in Exception class (or a subclass like ValueError, TypeError, etc.).