Creating a feedback loop
Being able to follow different courses of action based on different exceptions allows us to tailor our programs. For a DataError
or even a ProgrammingError
, we may want to handle the exception behind the scenes, hiding it from the user, but passing critical information to the development team. For Warning
or non-critical errors, we may choose to pause execution of the program and solicit more information from the user. To do this, we would use a raw_input
statement as part of the except
clause. In order to be concise, the following program treats errors and warnings the same way, but they could easily be separated and treated with greater granularity.
#!/usr/bin/env python import MySQLdb, sys mydb = MySQLdb.connect(host ='localhost', user = 'skipper', passwd = 'secret...