Python Program to Catch Multiple Exceptions in One Line – 2023

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Catch Multiple Exceptions in One Line.

Multiple exceptions as a parenthesized tuple

string = input()

    num = int(input())
except (TypeError, ValueError) as e:

Input 1


Output 1

can only concatenate str (not "int") to str

Input 2


Output 2

invalid literal for int() with base 10: 'b'
  • We have used try/except in this example.
  • It will first try to run the try part and will see if it runs successfully.
  • But if it throws any error, it will go in except part and there we have printed the Exception as e.
  • The exception can be of any type of 2 we have provided; TypeError or ValueError.

Check out our other python programming examples

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top