Built-in Exceptions

RuntimeWarning — exception class

Indicates questionable behavior at runtime, for example an unawaited coroutine. It differs from RuntimeError and may be suppressed or converted to an exception by filters. The example explicitly promotes this warning category to an exception to make the result independent of default filters. Catch RuntimeWarning when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
RuntimeWarning

Return Value

type

The class object RuntimeWarning; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
import warningstry:    with warnings.catch_warnings():        warnings.simplefilter("error", RuntimeWarning)        warnings.warn("demo", RuntimeWarning)except RuntimeWarning as error:    print(type(error).__name__)
Python Reference