Python Glossary Русский

all Python 3Exceptionsexception

ReferenceError

built-in exceptions

Accessing a weak-reference proxy to an object that has been garbage-collected.

Syntax

raise ReferenceError

Only weakref.proxy produces it: touching the proxy after its referent has been garbage-collected. A plain weakref.ref behaves differently — calling it simply returns None, so you check the result instead of wrapping the access in try. It is also unrelated to JavaScript's ReferenceError; an undefined name in Python raises NameError.

Examples

try:
    raise ReferenceError
except ReferenceError as e:
    print(type(e).__name__)   # → ReferenceError

Open in the full glossarydocs.python.orgReport an inaccuracy