#!/usr/bin/python
#import cgi;
#import cgitb; cgitb.enable()
txt_file = "crash_example_03.txt"
def main():
print "Content-type: text/html"
print
print "
Crashy Python Script"
print ""
print "Demonstration of what happens when you crash in your python cgi script & strategies to write better, more robust and debuggable code.
"
print "Key elements of this file:
"
print ""
print "- View the source here: %s
" % (txt_file, txt_file)
print "- printing from a function
"
print "- Slightly better try/except exception handling, now prints the contents of the the Exception
"
print "- Nothing will print after this line, the next line contains a div/0!
"
print "- This will crash: 1/0=%d
" % 1/0
print "
"
print "unreachable text"
if( __name__ == "__main__"):
try:
main()
except Exception, inst:
print "Uh oh! Something bad happened!"
print "
This message is generated in the 'except' block
"
print "Exception details:
"
print ""
print inst
print inst.args
print "
"
finally:
print ""