#coding:utf8
import sys
class MyException(Exception):
def __init__(self, value):
Exception.__init__(self)
self.value = value
def __str__(self):
return self.value
def raise_ex(args):
if args == 'err':
raise MyException('Invalid name is %s' % args)
else:
print('name: %s' % args)
if __name__ == '__main__':
name = input('请输入name:')
try:
f = raise_ex(name)
except Exception as e:
print('type %s ' % type(e))
print('sys info: %s' % sys.exc_info()[0])
print(e)
结果
请输入name:err
type <class '__main__.MyException'>
sys info: <class '__main__.MyException'>
Invalid name is err
<?php
$redis = new Redis();