javascript与php异常捕获
更新:HHH   时间:2023-1-7


  1. javascript:
    try{
    throw new Error("出错了");
    }catch(e){
    console.log(e.message)
    var stack = e.stack
    var exp = /\(.*\)/
    var ret = exp.exec(stack)
    console.log(ret[0])
    }finally{
    console.log("最后执行")
    }
  2. php:
    <?php
    try{
    throw new Exception('出错了');
    }catch(Exception $e){
    echo $e->getMessage().PHP_EOL;
    echo $e->getFile().PHP_EOL;
    echo $e->getLine().PHP_EOL;
    }finally{
    echo "最后执行\n";
    }
返回web开发教程...