-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorExample.py
More file actions
32 lines (26 loc) · 860 Bytes
/
errorExample.py
File metadata and controls
32 lines (26 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! python
import traceback
import logging
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
logging.debug('start of he program')
def factorial(n):
logging.debug('Start of factorial(%s)' % (n))
total = 1
for i in range(1,n + 1):
total *= i
logging.debug('i is ' + str(i) + ', total is ' + str(total))
logging.error('i is ' + str(i) + ', total is ' + str(total))
return total
def write_log():
errorFile = open('errorInfo.txt','w')
errorFile.write(traceback.format_exc())
errorFile.close()
print('the traceback info was written to errorInfo.txt')
factorial(5)
try:
raise Exception('This is the error message.')
except:
write_log()
door = 'open'
assert door == 'open','the door obviously needs to be "open" '
door = 'zzz'