pyspark.sql.functions.raise_error#

pyspark.sql.functions.raise_error(errMsg)[source]#

Throws an exception with the provided error message.

Added in version 3.1.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
errMsgColumn or literal string

A Python string literal or column containing the error message. A column that evaluates to a string.

Returns:
Column

throws an error with specified message. Returns a column that always evaluates to NULL.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.range(1).select(sf.raise_error("My error message")).show()
...
java.lang.RuntimeException: My error message
...