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

throw new 和new的区别

WBOY
WBOYOriginal
2016-06-06 20:31:282972browse

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

<code>}
</code>

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

回复内容:

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

<code>}
</code>

}
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>

就是抛出一个对象。

Statement:
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