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")
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")
python file open try except error
def FileCheck(fn):
try:
open(fn, "r")
return 1
except IOError:
print "Error: File does not appear to exist."
return 0
result = FileCheck("testfile")
print result
try except python
age = input('age:')
try:
new_age = int(age)
except ValueError: # if age is not convertable to int
print('please enter a number...')
python defualt error handler
import sys
def my_except_hook(exctype, value, traceback):
if exctype == KeyboardInterrupt:
print "Handler code goes here"
else:
sys.__excepthook__(exctype, value, traceback)
sys.excepthook = my_except_hook
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us