MemoryError

Built-in ExceptionPython 2.0+Intermediate

Raised when an operation runs out of memory

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching MemoryError
try:
    raise MemoryError("simulated memory error")
except MemoryError as e:
    print(f"Caught MemoryError: {e}")
    print(f"Type: {type(e).__name__}")

MemoryError is raised when raised when an operation runs out of memory. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore