[eluser]mrahman[/eluser]
Hi. I was searching the forum for 'exception handling' before asking this question...
Let me explain two scenarions:
1)
The first application i'm building with CI so far, is built with multilanguage support in the first hand. That is, i had to separate the fiew files each under a directory named as the language (english, arabic, russian, etc...). all resources like menus and images, all placed under its language. with one cool exception, the default language in $config['language'] is used whenever the requested url, in the selected language, was 404. Then the alternate default language file will be instead.
So, i had to check if the file_exists first. so i don't get the show_404, and load the default one instead.
And this file_exists() funciton, is what the framework does before loading the final viewfile, (i checked before, i'm sure it exists). now the application as a unit, checked for a single file,
twice!
this is one of the benifits of errors. i imagined i could write:
Code:
try
{
$this->load->view($requestedfile);
}
catch (FileNotFoundException $e)
{
try
{
$this->load->view($englishfile);
}
catch (FileNotFoundException $e404)
{
show_404();
}
}
Just imagined, because the loader class just show_404() and exit.
2)
A worse scenario could be when you are inserting a record in a table, with a primary key (say the ID field, and our new row has ID=100), you would check to see, for a duplicated pk value( a record with id=5), running a select count where id=5... The good or bad news is mysql will surely check for that pk violation anyway. even mysql checking procedure is definitely optimized than mine.
You could catch the constraint exception, a single check would be enough.
But now, we and our friend mysql made checking for id=5,
twice!
That's exceptions throwing... And then my opinion is making the framework graceful is not less important than being programmer friendly. In the two previous scenarios, that double checking decreases performance, hunting this sweet speed optimized framework.
Do you agree on this? is it what you need exception handling for?
Exception handling is new to PHP5.
Many greetings for CodeIgniter.
oh, so long message. sorry. sorry.
twice!