zl程序教程

您现在的位置是:首页 >  后端

当前栏目

php: 不能嵌套try-catch-fnally,否则执行时间过长

PHP执行 时间 不能 嵌套 try catch 过长
2023-09-14 08:57:52 时间

php不能try-catch-fnally里面在嵌套try-catch-fnall,否则本来执行时间不长的程序,会被执行更长时间,这是php的bug吗?

如:

      try{
          代码块
        }catch (\Exception $e)
        {
            echo get_class($e), ": ", $e->getMessage(), "\n";
            echo " File=", $e->getFile(), "\n";
            echo " Line=", $e->getLine(), "\n";
            echo $e->getTraceAsString();
        }finally{
           try{
             代码块
           }catch (\Exception $e)
           {
            echo get_class($e), ": ", $e->getMessage(), "\n";
            echo " File=", $e->getFile(), "\n";
            echo " Line=", $e->getLine(), "\n";
            echo $e->getTraceAsString();
           }finally{
              代码块
           }
        }

  应该改成:

         try{
             代码块
           }catch (\Exception $e)
           {
            echo get_class($e), ": ", $e->getMessage(), "\n";
            echo " File=", $e->getFile(), "\n";
            echo " Line=", $e->getLine(), "\n";
            echo $e->getTraceAsString();
           }finally{
              代码块
           }

            try{
             代码块
           }catch (\Exception $e)
           {
            echo get_class($e), ": ", $e->getMessage(), "\n";
            echo " File=", $e->getFile(), "\n";
            echo " Line=", $e->getLine(), "\n";
            echo $e->getTraceAsString();
           }finally{
              代码块
           }