Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

try and except in python

# Try & Except :-

# Try     => Test The Code For Errors
# Except  => Handle The Errors

# The Try & Except ==> Complete Each Other
# You Can't Type One Without The Other

# Example, We Need From The User To Write His Age
# Age Mean Integer
# But What If He Type String
# Of Course We Show To Him Wrong Message

try : # I Will Try The Code

  # If The User Type His Age, Mean Integer
  age = int( input( "Write Your Age Please: " ) ) 
  
  # This Message Will Show To Him
  print( f"Your Age Is {age}" ) 

except : # If I Found Error, I Will Show To Him Wrong Message

  # But If He Type Something Else, This Message Will Show To Him
  print( "Wrong Value, Please Try Again" ) 
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
9+3 =