dady4-exception handling

#!/usr/bin/env python
#coding:utf-8
#__author__:Bing

class MysqlError(Exception):
    def __init__(self,msg):
        self.error = msg
        
    def __str__(self):
        return self.error
try:
    if mysql.connect:
        print "login succes!"
    else:  
        raise MysqlError("login false .this is error log") #Manually create a log
except Exception,e:
    print e
相關文章
相關標籤/搜索