I know this is strange, but there are development mode errors and production mode errors in my code. This is the i function:
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 if an error occurs, I do not need to provide a check if we are in development mode or not!
So, I thought I could supplant the reusable code. However, since I selected an exception from this function, I mainly use a function that will return an error. Pretty useless in production mode.
I will need to do this every time I want to use it:
try{ $this -> error( "Invalid Link After Connect.", mysql_error () ); } catch ( Exception $exp ){ throw $exp; }
ANSWER THAN SIMPLY
$this -> error( "Invalid Link After Connect.", mysql_error () );
to avoid writing try ... catch block for each error function that I want to call ... is there a way to throw an exception at 2 levels?
source share