(PHP 5, PHP 7)
set_exception_handler — �����û��Զ�����쳣������
����Ĭ�ϵ��쳣�����������û���� try/catch ����������쳣��
�� exception_handler ���ú��쳣����ֹ��
exception_handler��һ��δ������쳣����ʱ�����ú��������ơ� �ô�������Ҫ����һ���������ò�����һ���׳����쳣���� PHP 7 ��ǰ���쳣�������ǩ����
�� PHP 7 ����������������׳� Error �쳣��Ҳ�ܱ����� Error �� Exception ��ʵ���� Throwable �ӿڡ� PHP 7 �𣬴�������ǩ����
$ex
) : void
Ҳ���Դ��� NULL ֵ���������쳣������ΪĬ��ֵ��
ע�⣬������û��ص��ォ ex ������������ȷԼ��ΪException�� PHP 7 �������쳣���͵ı仯������������⡣
����֮ǰ������쳣�����������ƣ������ڴ���ʱ���� NULL��
���֮ǰû�ж�����������Ҳ�᷵�� NULL��
| �汾 | ˵�� |
|---|---|
| 7.0.0 |
���� exception_handler �IJ����� Exception ��Ϊ Throwable
|
| 5.5.0 |
֮ǰ�汾�������� NULL �������᷵�� TRUE��
�� PHP 5.5.0 �᷵����һ�ε��쳣��������
|
Example #1 set_exception_handler() ����
<?php
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?>