How to use PHP's built-in classes in namespaces

Source: Internet
Author: User
How do I use PHP's built-in classes in namespaces?
Hello, beginner PHP, encounter problems, ask for advice:
This is the code in a php file. Contains 2 namespaces, Test2 and Test4, Exception class throws an error in Test2
Errors are detected in the test4 space, but the runtime says that the exception class is not found in test2, so the exception class in the Red section
The previous add \ Indicates the root space, but in test4 the catch statement Exception $e error
How can I change the correct, thank you.
Namespace test2{
Class a{
Private $file _id;

Public Function File_open ($path _file_name) {
$this->[email protected] ($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) {...}

}

------Solution--------------------
catch (\exception $e)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.