Answers for "how to do exception handling in python"

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
9

except as Exception:

>>> def catch():
...     try:
...         asd()
...     except Exception as e:
...         print e.message, e.args
... 
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
Posted by: Guest on April-28-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
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
0

error handling in python

try:
  print(x)
except SyntaxError:
  print("There is a SyntaxError in your code")
except NameError:
  print("There is a NameError in your code")
except TypeError:
  print("There is a TypeError in your code")
Posted by: Guest on September-08-2020

Code answers related to "how to do exception handling in python"

Python Answers by Framework

Browse Popular Code Answers by Language