php, can exceptions be thrown 2 levels up?

前端 未结 3 1232
滥情空心
滥情空心 2021-01-18 07:19

I know this is a weird on, but in my code, i have development mode errors, and production mode errors. This is the function i have:

private function error($m         


        
3条回答
  •  北海茫月
    2021-01-18 07:43

    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 () );
    

提交回复
热议问题