PHP try/catch and fatal error

前端 未结 6 1860
庸人自扰
庸人自扰 2020-12-10 01:01

I\'m using the following script to use a database using PHP:

try{
    $db = new PDO(\'mysql:host=\'.$host.\';port=\'.$port.\';dbname=\'.$db, $user, $pass, $o         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 01:38

    In PHP7, we now can using try catch fatal error with simple work

    try {
       do some thing evil
    } catch (Error $e) {
       echo 'Now you can catch me!';
    }
    

    But usualy, we should avoid using catch Error, because it involve to miss code which is belong to programmer's reponsibility :-)

提交回复
热议问题