Answers for "python except error"

16

how to print error in try except python

try:
  # some code
except Exception as e:
	print("ERROR : "+str(e))
Posted by: Guest on November-19-2020
2

catch error python

import traceback

dict = {'a':3,'b':5,'c':8}
try:
  print(dict[q])
 
except:
  traceback.print_exc()
  
# This will trace you back to the line where everything went wrong. 
# So in this case you will get back line 5
Posted by: Guest on October-25-2020
2

error handling Pyhtin

# taking input from the user 
try:
    age = int(input("Please enter your age: "))
    print(age)
except:
    print("please enter a number instead! ")
    print('bye')


# if you wanna ask their age until they enter the correct number use While Loop
while True:
    try:
        age = int(input("Please enter your age: "))
        print(age)
    except:
        print("please enter a number instead! ")
    else:
        break
Posted by: Guest on January-10-2021
25

try except python

try:
  print("I will try to print this line of code")
except ERROR_NAME:
  print("I will print this line of code if error ERROR_NAME is encountered")
Posted by: Guest on February-01-2020
9

python exception

try:
   # Code to test / execute
   print('Test')
except (SyntaxError, IndexError) as E:  # specific exceptions
   # Code in case of SyntaxError for example
   print('Synthax or index error !')
except :
   # Code for any other exception
   print('Other error !')
else:
   # Code if no exception caught
   print('No error')
finally:
   # Code executed after try block (success) or any exception (ie everytime)
   print('Done')

# This code is out of try / catch bloc
print('Anything else')
Posted by: Guest on April-19-2021
6

python error handling

try:
	#insert code here
except:
	#insert code that will run if the above code runs into an error.
except ValueError:
	#insert code that will run if the above code runs into a specific error.
	#(For example, a ValueError)
Posted by: Guest on September-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language