Home > Backend Development > PHP Tutorial > Exception Handling - What is the difference between Exception and Exception in php?

Exception Handling - What is the difference between Exception and Exception in php?

WBOY
Release: 2016-07-06 13:52:10
Original
1051 people have browsed it

You need to catch an exception in the code. Using catch(Exception $e) is invalid, but changing it to catch(Exception $e) will do. I probably know it has something to do with namespaces, but I don't understand the specifics. Please give me an answer. In addition, I found that other places in this file that use exceptions use (Exception $e) instead of (Exception $e)

Reply content:

You need to catch an exception in the code. Using catch(Exception $e) is invalid, but changing it to catch(Exception $e) will do. I probably know that it has something to do with namespaces, but I don't quite understand the details. Please give me some answers. In addition, I found that other places in this file that use exceptions use (Exception $e) instead of (Exception $e)

If your PHP file defines a namespace, then the class usage under the namespace must add
to indicate the root space, which is PHP's own class, not the class in your PHP file

The reason why it cannot be caught may be that the exceptions thrown do not match. Check whether the exception classes thrown by other exceptions have a layer of inheritance relationship. .

Qing Mi is right.

If your PHP file defines a namespace, catch(Exception $e) will look for the Exception class under the namespace. If it is not defined, the problem of not finding the class will occur.

catch(Exception $e) represents the root space, and this class always exists.

Recommended to read modern php this book.

Exception represents the root namespace. To put it bluntly, it is the official exception class of PHP. If not added, it may be a class under the namespace you currently define

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template