25 Nov
Posted by Ganesh H S , Bangalore, India as zend framework
As in other object oriented programming languages, zend framework supports try catch, all exceptions thrown by Zend Framework classes should throw an exception that derives from the base class Zend_Exception.
Example 1:
In this example, code require_once “Zend_Loader.php”; is commented, so error is thrown when we are trying to access Zend_Loader.
<?php
//require_once "Zend_Loader.php";
try
{
Zend_Loader::loadClass('Zend_Session');
}
catch (Zend_Exception $e) {
echo "Error message: " . $e->getMessage() . "\n";
}
?>
Example 2:
In this example, $sql does not have a closing double quote, so the error thrown is catched and is printed.
<?php
/**
* Zend Loader
*/
require_once "Zend/Loader.php";
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Config_Ini');
/**
* Set config
*/
$config = new Zend_Config_Ini("../application/config.ini", "staging");
/**
* Set the database
*/
// setup database
$db = Zend_Db::factory($config->db->adapter,
$config->db->config->toArray());
try
{
$sql = "SELECT count(*) FROM TABLE_NAME";
$db->fetchOne($sql) ;
}
catch (Zend_Exception $e) {
{
echo "Db error : " . $e->getMessage() . "\n";
}
?>
Reference Links:
http://ganeshhs.com/zend-framework/zend-framework-tutorial-part-4-zend-config
http://ganeshhs.com/zend-framework/zend-framework-tutorial-part-3-zend-loader
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Jul | ||||||
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
RSS feed for comments on this post · TrackBack URI
Leave a reply