🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.7 documentation
>>> 10 * (1/0) Traceback (most recent call last): File "<stdin>", line 1, in <module> 10 * (1/0) ~^~ ZeroDivisionError: division by zero >>> 4 + spam*3 Traceback (most recent call last): File "<stdin>", line 1, in <module> 4 + spam*3 ^^^^ NameError: name 'spam' is not defined >>> '2' + 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> '2' + 2 ~~~~^~~ TypeError: can only concatenate str (not "int") to str · The last line of the error message indicates what happened.
🌐
GeeksforGeeks
geeksforgeeks.org › python › errors-and-exceptions-in-python
Errors and Exceptions in Python - GeeksforGeeks
May 29, 2026 - On the other hand, exceptions are raised when some internal events change the program's normal flow. A syntax error occurs when the code does not follow Python’s writing rules. Python detects these errors before running the program and shows the location of the mistake.
Discussions

29 common beginner Python errors in one flowchart
About the equality check returning True instead of False in if-clauses: I think python protects against using = instead of == and raises a SyntaxError. More on reddit.com
🌐 r/Python
43
327
August 6, 2013
python - How do I determine what type of exception occurred? - Stack Overflow
In such a case, you should catch ... and if in debug mode, enter post-mortem. 2012-03-22T19:17:57.843Z+00:00 ... @RikPoggi: Naive thinking. There are many reasonable circumstances when you need to catch exceptions from someone else's code and you don't know what exceptions will be raised. 2016-10-01T00:37:22.163Z+00:00 ... This postmortem trick helped me narrow down an exception type of objc.error which is sort ... More on stackoverflow.com
🌐 stackoverflow.com
Common Python error types and how to resolve them

Thank you so much, this is nice to have with learning :)

More on reddit.com
🌐 r/pythontips
2
1
February 3, 2025
What's the difference between error and exception in Python?
An error is when you make a mistake. An Exception is a class in python that generates messages and categorizes code that could be mistakes. Technically there are no errors in python. The terms Exception and error are used interchangeably, to the point that most Exceptions have the word Error in their name, but all these "Errors" are really "Exceptions". More on reddit.com
🌐 r/learnpython
9
5
January 26, 2021
People also ask

What is the most common error in Python?
For beginners, SyntaxError and IndentationError are the most frequent, since both come from formatting rather than logic. Among runtime exceptions, TypeError, NameError, and KeyError are the ones you meet most often in day-to-day code.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
What is the difference between an error and an exception in Python?
An exception is the object Python raises when something goes wrong at runtime, and your code can catch it with try and except. "Error" is the broader word, and it also covers syntax errors, which cannot be caught this way because the file never runs. In practice most runtime errors are exceptions, which is why the two terms are often used interchangeably.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
How do you find a logical error in Python?
Logical errors raise nothing, so the interpreter cannot help. Compare the output you got against the output you expected on a small input you can verify by hand, then narrow the gap with print statements, a debugger, or unit tests that assert the expected result. Code review is effective here because the bug is in the reasoning, not the syntax.
🌐
last9.io
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained ...
🌐
Last9
last9.io › blog › types-of-errors-in-python
Types of Errors in Python: Syntax, Runtime, and Logical Explained | Last9
January 3, 2025 - Python errors fall into three types: syntax errors, runtime errors, and logical errors. A syntax error stops your code before it runs. A runtime error stops it partway through execution.
🌐
W3Schools
w3schools.com › python › python_ref_exceptions.asp
Python Built-in Exceptions
The table below shows built-in exceptions that are usually raised in Python.
🌐
Honeybadger
honeybadger.io › blog › errors-in-python
Errors in Python: Types, Causes, and Examples - Honeybadger Developer Blog
April 27, 2026 - Runtime errors occur in a Python program after it passes the syntax check and starts executing, when something goes wrong. Examples of runtime errors in Python include ZeroDivisionError, NameError, TypeError, and ValueError.
🌐
Quora
quora.com › How-many-types-of-errors-are-in-Python-programming
How many types of errors are in Python programming? - Quora
Answer: There are several types of errors that can occur in Python. Each type indicates a different kind of problem in the code, and comprehending these error types is crucial in creating effective Python applications. The most common types of errors you'll encounter in Python are syntax errors,...
Find elsewhere
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Passing arguments of the wrong type (e.g. passing a list when an int is expected) should result in a TypeError, but passing arguments with the wrong value (e.g. a number outside expected boundaries) should result in a ValueError. ... Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of NameError. ... Raised when a Unicode-related encoding or decoding error occurs.
🌐
Tutorial Teacher
tutorialsteacher.com › python › error-types-in-python
Error Types in Python
Learn about built-in error types in Python such as IndexError, NameError, KeyError, ImportError, etc.
🌐
Reddit
reddit.com › r/python › 29 common beginner python errors in one flowchart
r/Python on Reddit: 29 common beginner Python errors in one flowchart
August 6, 2013 - Most of this is common errors in all languages, if you replace Python lingo with C#, C, Java, PHP... Shows how similar the foundations are in all languages. ... There's a bit of a difference, in that many of these errors will be compile-time in many statically typed language: AttributeError, TypeError, NameError, storing the result of a void function/method, ...
🌐
Rollbar
rollbar.com › home › what are the different types of python errors? – and how to handle them
What are the Different Types of Python Errors? – and How to Handle Them
Now the code will run without any errors, and the output will be 500, which is the element at index 4 of the list. An AttributeError occurs when you try to access an attribute or method that doesn't exist for a particular object type. This often happens due to typos or misunderstanding what methods are available for different data types. Here's an example of an AttributeError in Python:
Published: July 14, 2025
Top answer
1 of 16
621

The other answers all point out that you should not catch generic exceptions, but no one seems to want to tell you why, which is essential to understanding when you can break the "rule". Here is an explanation. Basically, it's so that you don't hide:

  • the fact that an error occurred
  • the specifics of the error that occurred (error hiding antipattern)

So as long as you take care to do none of those things, it's OK to catch the generic exception. For instance, you could provide information about the exception to the user another way, like:

  • Present exceptions as dialogs in a GUI
  • Transfer exceptions from a worker thread or process to the controlling thread or process in a multithreading or multiprocessing application

So how to catch the generic exception? There are several ways. If you just want the exception object, do it like this:

try:
    someFunction()
except Exception as ex:
    template = "An exception of type {0} occurred. Arguments:\n{1!r}"
    message = template.format(type(ex).__name__, ex.args)
    print(message)

Make sure message is brought to the attention of the user in a hard-to-miss way! Printing it, as shown above, may not be enough if the message is buried in lots of other messages. Failing to get the users attention is tantamount to swallowing all exceptions, and if there's one impression you should have come away with after reading the answers on this page, it's that this is not a good thing. Ending the except block with a raise statement will remedy the problem by transparently reraising the exception that was caught.

The difference between the above and using just except: without any argument is twofold:

  • A bare except: doesn't give you the exception object to inspect
  • The exceptions SystemExit, KeyboardInterrupt and GeneratorExit aren't caught by the above code, which is generally what you want. See the exception hierarchy.

If you also want the same stacktrace you get if you do not catch the exception, you can get that like this (still inside the except clause):

import traceback
print traceback.format_exc()

If you use the logging module, you can print the exception to the log (along with a message) like this:

import logging
log = logging.getLogger()
log.exception("Message for you, sir!")

If you want to dig deeper and examine the stack, look at variables etc., use the post_mortem function of the pdb module inside the except block:

import pdb
pdb.post_mortem()

I've found this last method to be invaluable when hunting down bugs.

2 of 16
167

Get the name of the class that exception object belongs:

e.__class__.__name__

and using print_exc() function will also print stack trace which is essential info for any error message.

Like this:

from traceback import print_exc

class CustomException(Exception): pass

try:
    raise CustomException("hi")
except Exception as e:
    print ('type is:', e.__class__.__name__)
    print_exc()
    # print("exception happened!")

You will get output like this:

type is: CustomException
Traceback (most recent call last):
  File "exc.py", line 7, in <module>
    raise CustomException("hi")
CustomException: hi

And after print and analysis, the code can decide not to handle exception and just execute raise:

from traceback import print_exc

class CustomException(Exception): pass

def calculate():
    raise CustomException("hi")

try:
    calculate()
except CustomException as e:
    # here do some extra steps in case of CustomException
    print('custom logic doing cleanup and more')
    # then re raise same exception
    raise

Output:

custom logic doing cleanup and more

And interpreter prints exception:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    calculate()
  File "test.py", line 6, in calculate
    raise CustomException("hi")
__main__.CustomException: hi

After raise original exception continues to propagate further up the call stack. (Beware of possible pitfall) If you raise new exception it caries new (shorter) stack trace.

from traceback import print_exc

class CustomException(Exception):
    def __init__(self, ok):
        self.ok = ok

def calculate():
    raise CustomException(False)

try:
    calculate()
except CustomException as e:
    if not e.ok:
        # Always use `raise` to rethrow exception
        # following is usually mistake, but here we want to stress this point
        raise CustomException(e.ok)
    print("handling exception")

Output:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    raise CustomException(e.message)
__main__.CustomException: hi    

Notice how traceback does not include calculate() function from line 9 which is the origin of original exception e.

🌐
ATS-PL-SYS
cs.bu.edu › courses › cs111 › problem_sets › errors.shtml
CS 111: Python Errors
The most common type of error, a syntax error occurs when the interpreter is reading the Python file to determine if it is valid Python code and encounters something it doesn’t “understand”. The interpreter will check things like indentation, use of parentheses and square brackets, proper ...
🌐
Miguel Grinberg
blog.miguelgrinberg.com › post › the-ultimate-guide-to-error-handling-in-python
The Ultimate Guide to Error Handling in Python - miguelgrinberg.com
As discussed above, in Python the preferred mechanism to notify the caller of an error is to raise an exception, so this is what we'll do. This strategy works well because of an interesting property of non-recoverable errors. In most cases, a non-recoverable error will eventually become recoverable when it reaches a high enough position in the call stack. So the error can bubble up the call stack until it becomes recoverable, at which point it'll be a type 2 error, which we know how to handle.
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter10.01-Error-Types.html
Error Types — Python Numerical Methods
There are three basic types of errors that programmers need to be concerned about: Syntax errors, runtime errors, and Logical errors. Syntaxis the set of rules that govern a language. In written and spoken language, rules can be bent or even broken to accommodate the speaker or writer.
🌐
Carleton University
cs.carleton.edu › cs_comps › 1213 › pylearn › final_results › encyclopedia › typeError.html
Error Encyclopedia | Type Error
# a string >>> [2, 13, 10] # a list (containing three objects of type int) >>> (5, 0, 7) # a tuple --- much like a list, but it can't ever be modified · When you call a function or use an operator in Python, it typically expects to be given parameters of a specific type.
🌐
Real Python
realpython.com › python-exceptions
Python Exceptions: An Introduction – Real Python
March 18, 2026 - This time, you ran into an exception error. This type of error occurs whenever syntactically correct Python code results in an error.
🌐
Towards Data Science
towardsdatascience.com › home › latest › most common python error types in data science
Most Common Python Error Types in Data Science | Towards Data Science
January 18, 2025 - # Trying to assign total_bill to ... or use proper quote marks for variable names. TypeError pops when a function or operation is applied to an object of an incorrect type....
🌐
Mimo
mimo.org › glossary › python › error-handling
Python Error Handling: Syntax, Techniques, and Best Practices
Syntax errors occur when the interpreter encounters code that violates Python's grammar rules. These are caught before execution begins. ... These happen during execution and stop the normal flow of the program. ... Python includes many built-in exception types.
🌐
MDPI
mdpi.com › 2079-3197 › 14 › 4 › 86
Python-Assisted Development of High-Performance Fortran Codes: A Hybrid Methodology Integrating Symbolic Mathematics and Large Language Models
April 6, 2026 - Type system errors (incorrect type declarations, array handling mistakes); Undefined symbol references due to missing declarations or incorrect module usage. LLMs should not be used for directly generating production Fortran code.
🌐
Stripe
docs.stripe.com › api › errors
Errors | Stripe API Reference
Our Client libraries raise exceptions for many reasons, such as a failed charge, invalid parameters, authentication errors, and network unavailability. We recommend writing code that gracefully handles all possible API exceptions. ... Many objects allow you to request additional information ...