Monday, November 24, 2025
HomeLanguagesHandling EOFError Exception in Python

Handling EOFError Exception in Python

EOFError is raised when one of the built-in functions input() or raw_input() hits an end-of-file condition (EOF) without reading any data. This error is sometimes experienced while using online IDEs. This occurs when we have asked the user for input but have not provided any input in the input box. We can overcome this issue by using try and except keywords in Python. This is called as Exception Handling.

Example: This code will generate an EOFError when there is no input given to the online IDE.

Python3




n = int(input())
print(n * 10)


Output:

This exception can be handled as:

Python3




try:
    n = int(input())
    print(n * 10)
    
except EOFError as e:
    print(e)


Output:

EOF when reading a line
RELATED ARTICLES

Most Popular

Dominic
32411 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6787 POSTS0 COMMENTS
Nicole Veronica
11934 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6910 POSTS0 COMMENTS
Ted Musemwa
7169 POSTS0 COMMENTS
Thapelo Manthata
6868 POSTS0 COMMENTS
Umr Jansen
6855 POSTS0 COMMENTS