使异常处理变得更灵活.可观察,可以使用设计模式中的观察者模式. 文件 ① 定义观察者的接口 ExceptionObserver.php: <?php /* 给观察者定义的规范 */ interface ExceptionObserver{ public function update(Observer_Exception $e); } 文件 ② 观察者模式的自定义异常类 Observer_Exception Observer_Exception.php: <?php class Observe
笔记-python异常信息输出 1. 异常信息输出 python异常捕获使用try-except-else-finally语句: 在except 语句中可以使用except as e,然后通过e得到异常信息: str(e): # 返回字符串类型,只给出异常信息,不包括异常信息的类型,如I/O的异常信息. division by zero repr(e): #给出较全的异常信息,包括异常信息的类型 ZeroDivisionError('division by zero',) e.mess