你好,初学php,遇到问题,求教:
一下是一个php 文件中的代码。包含了2个名字空间,test2 和test4 , 在test2中 Exception 类抛出错误
在test4 空间中检测错误,但是运行时说 test2 中找不到 Exception类,所以在红色部分的 Exception类
前面添加 \ 指明根空间,但是在 test4 中又提示 catch 语句中 Exception $e 错误
请问我该如何修改才正确,谢谢。
namespace test2{
  class A{
    private $file_id ;
    
    public function file_open($path_file_name){
      $this->file_id=@fopen($path_file_name , 'r');
      if($this->file_id==false){ throw new \Exception("path_file_name isnot EXIST"); 
        echo(nl2br(sprintf("file open failed\n"))); }
    }
  }
}namespace test4{
  use test2;
  try{
    $obj_A = new test2\A();
    $path_name = "/home/zhiys/php/111.php";
    $obj_A->file_open($path_name) ;
  }catch(Exception $e){ ... }     }