Home > Backend Development > PHP Tutorial > throw new 和new的区别

throw new 和new的区别

WBOY
Release: 2016-06-06 20:31:28
Original
2975 people have browsed it

class a extends Exception{
function __construct(){
parent::__construct('a',1);

<code>}
</code>
Copy after login
Copy after login

}
throw new a(12,1);
这俩有啥区别,用了好久了,刚才好奇就想出来一个这么个问题

回复内容:

class a extends Exception{
function __construct(){
parent::__construct('a',1);

<code>}
</code>
Copy after login
Copy after login

}
throw new a(12,1);
这俩有啥区别,用了好久了,刚才好奇就想出来一个这么个问题

<code>try {
    $obj = new Exception('12', 1);
    throw $obj;
} catch (Exception $e) {
    print_r($e);
}
//=======================这是等价的
try {
    throw new Exception('12', 1);
} catch (Exception $e) {
    print_r($e);
}
</code>
Copy after login

就是抛出一个对象。

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