Built-in Exceptions
NotADirectoryError — exception class
A directory operation or path traversal requires a directory but a component is not one. Inspect the full path, not just its final component. The example uses the symbolic errno.ENOTDIR 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 NotADirectoryError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
NotADirectoryErrorReturn Value
type
The class object NotADirectoryError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
import errnotry: raise OSError(errno.ENOTDIR,"demo")except NotADirectoryError as error: print(type(error).__name__)