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($message, $mysql_error = null){ if( DEVELOPMENT_MODE ){ $exp = new Exception(); $trace = $exp -> getTrace(); array_shift( $trace ); // removes this functions from trace $data["Error Mg"] = $message; $data["MySQL Er"] = ( is_null ( $mysql_error ) ) ? "" : $mysql_error; array_unshift($trace, $data ); fkill( $trace ); // formats array and then dies } else{ throw new Exception ( $data ); } } I wrote this function in my database class, so that if an error happens, I don't have to provide the check if we're in development mode or not!
So I thought I could externalise the re-usable code. However, because I'm throwing an exception from this function, I'm basically just using a function, that will return a thrown error. Pretty useless in production mode.
I would have to do this every time i want to use it:
try{ $this -> error( "Invalid Link After Connect.", mysql_error () ); } catch ( Exception $exp ){ throw $exp; } RATHER THAN JUST
$this -> error( "Invalid Link After Connect.", mysql_error () ); so to avoid writing a try ... catch block for every error function I want to call... is there any way to throw the exception 2 levels up?
I would have to do this every time i want to use it:Why's that?