try and catch block in php

Thursday, October 30, 2008 8:47
Posted in category PHP, Programming

Exception handling is used to change the normal flow of the code execution if a specified error (exceptional) condition occurs. This condition is called an exception.
Try block is used to try for the code to execute if any error like file unable to open etc.. It will stop the execution and it will throw exception like file not found exception.. We can catch this exception in catch block.. If try will not throw any exception catch block never execute.

try {

//open a file which is not existing

$row = $this->db->fetchRow( $sql );

return $row;

}

catch( Exception $e ) {

// does some custom error handling

mysqlErrorCheck( $e, __LINE__, __FILE__ );

} 
You can leave a response, or trackback from your own site.

One Response to “try and catch block in php”

  1. uefi fix says:

    April 1st, 2011 at 3:24 am

    Very clean web site , appreciate it for this post. scripts

Leave a Reply