pyspark.sql.functions.raise_error

pyspark.sql.functions.raise_error(errMsg: Union[pyspark.sql.column.Column, str]) → pyspark.sql.column.Column[source]

Throws an exception with the provided error message.

New in version 3.1.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
errMsgColumn or str

A Python string literal or column containing the error message

Returns
Column

throws an error with specified message.

Examples

>>> df = spark.range(1)
>>> df.select(raise_error("My error message")).show() 
...
java.lang.RuntimeException: My error message
...