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.
🌐
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.
Find elsewhere
🌐
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.
🌐
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_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.
🌐
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.
🌐
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 › 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 »...
🌐
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.).
🌐
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 › python_ref_exceptions.asp
Python Built-in Exceptions
HTML Certificate CSS Certificate JavaScript Certificate Front End Certificate SQL Certificate Python Certificate PHP Certificate jQuery Certificate Java Certificate C++ Certificate C# Certificate XML Certificate ... W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
🌐
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
🌐
W3Schools
w3schools.in › python › examples
Python Programming Examples Index - W3Schools
Python Programming Examples Index · 51 Examples · © 2009 — 2026 W3schools® of Technology · About Us · Support Us · Contact Us