Built-in Exceptions

FileExistsError — exception class

A creation operation requires a new path but the path already exists. Choose a unique destination or explicitly decide whether existing data can be reused; avoid accidental overwrites. The example uses the symbolic errno.EEXIST to demonstrate CPython exception selection without accessing an external system. The example raises a controlled stand-in to demonstrate handling; it does not cause the real system failure. Catch FileExistsError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
FileExistsError

Return Value

type

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

Working Example

Example Snippetpython
import errnotry:    raise OSError(errno.EEXIST,"demo")except FileExistsError as error:    print(type(error).__name__)
Python Reference