If you literally want to raise an exception only on the empty string, you'll need to do that manually:

try:
    user_input = input() # raw_input in Python 2.x
    if not user_input:
        raise ValueError('empty string')
except ValueError as e:
    print(e)

But that "integer input" part of the comment makes me think what you really want is to raise an exception on anything other than an integer, including but not limited to the empty string.

If so, open up your interactive interpreter and see what happens when you type things like int('2'), int('abc'), int(''), etc., and the answer should be pretty obvious.

But then how do you distinguish an empty string from something different? Simple: Just do the user_input = input() before the try, and check whether user_input is empty within the except. (You put if statements inside except handlers all the time in real code, e.g., to distinguish an OSError with an EINTR errno from one with a different errno.)

Answer from abarnert on Stack Overflow
🌐
Python
docs.python.org › 3 › library › exceptions.html
Built-in Exceptions — Python 3.14.5 documentation
It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no ...
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 381248 › using-try-except-to-catch-a-blank-input
python - Using Try, Except to catch a blank input [SOLVED] | DaniWeb
In python 3, after result = input(prompt) , result is a string in the python sense (an instance of the datatype 'str'). Examples of strings are · "" # the empty string " " # a string of white space "3.14159" # a string with the representation … — Gribouillis 1,391 Jump to Post · You can pass the acceptable values to the checkInput() function and let it do the work. For the getFloat() function, use a try/except to test for correct input.
🌐
w3resource
w3resource.com › python-exercises › extended-data-types › python-extended-data-types-none-exercise-1.php
Python function to handle empty strings
August 11, 2025 - Write a Python function that takes a string as input and returns "None" if the string is empty, otherwise it returns the given string. ... def check_string(input_string): if not input_string: return "None" return input_string def main(): try: ...
🌐
CopyProgramming
copyprogramming.com › howto › python-empty-list-exception
Python: Exception Raised When Using an Empty List in Python
April 9, 2023 - Empty tuple as argument to except in python, The answer is 1: no exceptions, in Python 2 and in Python 3. exceptions = () try: a = 1 / 0 except exceptions as e: print ("the answer is 2") Traceback (most recent call last): File "<pyshell#38>", line 2, in <module> a = 1 / 0 ZeroDivisionError: integer division or modulo by zero. If you want to the … ... In the try clause, I am assigning values to multiple variables . However, I need an except clause that sets an empty string only for the variables that are unavailable.
🌐
CodeQL
codeql.github.com › codeql-query-help › python › py-empty-except
Empty except — CodeQL query help documentation
An empty except block may be an indication that the programmer intended to handle the exception, but never wrote the code to do so. Ensure all exceptions are handled correctly. In this example, the program keeps running with the same privileges if it fails to drop to lower privileges.
Find elsewhere
🌐
Python
docs.python.org › 3.13 › library › exceptions.html
Built-in Exceptions — Python 3.13.3 documentation
It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no ...
🌐
University of Toronto
teach.cs.toronto.edu › ~csc148h › winter › notes › abstract-data-types › exceptions.html
3.3 Exceptions
class EmptyStackError(Exception): """Exception raised when calling pop on an empty stack.""" def __str__(self) -> str: """Return a string representation of this error.""" return 'You called pop on an empty stack.
🌐
Python
docs.python.org › 3.14 › library › exceptions.html
Built-in Exceptions — Python 3.14.0b1 documentation
It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no ...
🌐
Python
docs.python.org › 3 › library › exceptions.html
Built-in Exceptions — Python 3.14.4 documentation
It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no ...
🌐
Python
docs.python.org › 3 › c-api › exceptions.html
Exception Handling — Python 3.14.5 documentation
This function sets the error indicator and returns NULL. exception should be a Python exception class. The format and subsequent parameters help format the error message; they have the same meaning and values as in PyUnicode_FromFormat(). format is an ASCII-encoded string.
🌐
Python
docs.python.org › 3.15 › library › exceptions.html
Built-in Exceptions — Python 3.15.0a2 documentation
It is not meant to be directly inherited by user-defined classes (for that, use Exception). If str() is called on an instance of this class, the representation of the argument(s) to the instance are returned, or the empty string when there were no ...
🌐
Sentry
sentry.io › sentry answers › python › check if a string is empty in python
Check if a string is empty in Python | Sentry
May 15, 2023 - if my_string.strip() == "": print("my_string is an empty string!") else: print("my_string is not an empty string!") ... Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski. SEE EPISODES ... David Y. — July 15, 2023 · Difference between `@staticmethod` and `@classmethod` function decorators in Python