Yes, It is possible to write programs that handle all the exceptions. But it is not advisable to handle all the exceptions such as KeyboardInterrupt exception. Look at the example below, which asks the user for input until a valid integer has been entered, but allows the user to interrupt the program (using Control-C or whatever the operating system supports); note that a user-generated interrupt is signaled by raising the KeyboardInterrupt exception.
What is KeyboardInterrupt exception():-
This exception is raised when the user hits the interrupt key (normally Control-C or Delete). During execution, a check for interrupts is made regularly. The exception inherits from BaseException so as to not be accidentally caught by code that catches Exception and thus prevents the interpreter from exiting.
This examples also illustrate how we handle exceptions:-
while True:
try:
x = int(input("Please enter a number: "))
break
except ValueError:
print("Oops! That was no valid number. Try again...")