Built-in Exceptions
ResourceWarning — exception class
Signals resource-management concerns such as resources left unclosed. Usually ignored by default; use context managers and explicit cleanup rather than rely on finalization warnings. The example explicitly promotes this warning category to an exception to make the result independent of default filters. Catch ResourceWarning when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
ResourceWarningReturn Value
type
The class object ResourceWarning; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
import warningstry: with warnings.catch_warnings(): warnings.simplefilter("error", ResourceWarning) warnings.warn("demo", ResourceWarning)except ResourceWarning as error: print(type(error).__name__)