Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #catch exception
- try :
- #throws exception if the input is not a number
- number = int(input())
- print(str(number))
- except ValueError:
- print('error in input')
- printNumberInput()
- #raise exception
- def myFunction(symbol)
- if len(symbol) != 1 :
- raise Exception('The symbol lenght should be one')
- print(symbol)
- #avoid to crash when we raise an exception but log all the
- #errors as callstack to a separated log file
- import traceback
- try :
- raise Exception('Error message')
- except :
- errorFile = open('error_log.txt','a')
- errorFile.write(traceback.format_exc())
- errorFile.close()
- print('wrote callstack to the error log file')
- #assertion
- assert False, 'exception message' # they are threated as exception
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement