#!/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