php, can exceptions be thrown 2 levels up?

 ̄綄美尐妖づ 提交于 2019-12-01 18:16:24

An exception will automatically travel up the call chain until it reaches the highest level. If it's not caught there, program execution terminates due to an uncaught exception. The whole point of exceptions is to be able to have errors bubble up. You don't need to throw harder or do anything special to "throw it up 2 levels", that's what it does by definition.

Just omit the try/catch block. Exceptions automatically propagate up as far as they can until something catches them; you don't need to explicitly re-throw them at every level of the call stack.

This...

try{
    $this -> error( "Invalid Link After Connect.", mysql_error () );
} catch ( Exception $exp ){
    throw $exp;
}

is exactly equivalent to this:

$this -> error( "Invalid Link After Connect.", mysql_error () );

Use Multiple catch Blocks use admin table which has field

Mode    Value 
0     Production
1     Debug     

the first catch which matches the exception is executed

Example

 try {

    if (!$bDBConnection && $row['mode'] ==0 ) {
       throw new Produciton_DBException("Problem with Database");
    }
    else
    {
        throw new Debug_DBException("Problem with Database");
    }

 }
 catch(Produciton_DBException $e)
 {

  // display suitable error messages
 }
 catch(Debug_DBException $ex)
 {
   // Exception falls through until a match is found
 } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!