Built-in Exceptions
ImportWarning — exception class
Signals potential import-system problems; typically ignored by default. It is not an ImportError and need not prevent importing a module. The example explicitly promotes this warning category to an exception to make the result independent of default filters. Catch ImportWarning when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
ImportWarningReturn Value
type
The class object ImportWarning; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
import warningstry: with warnings.catch_warnings(): warnings.simplefilter("error", ImportWarning) warnings.warn("demo", ImportWarning)except ImportWarning as error: print(type(error).__name__)