Conditional exceptions.
Posted: Sun Jan 18, 2009 10:28 am
Hello,
I find exceptions very handy, but I do not like the performance drop they give me. So I'm wondering if I could use conditional exception throwing, how does PHP handle this - is it ok? I mean that do I avoid my performance drop this way. On production level the functions would just return false and tell something went wrong and in development level all details are printed out and logged. Of course the production version could also log the problem.
Look at this sample code:
What are your thoughts?
I find exceptions very handy, but I do not like the performance drop they give me. So I'm wondering if I could use conditional exception throwing, how does PHP handle this - is it ok? I mean that do I avoid my performance drop this way. On production level the functions would just return false and tell something went wrong and in development level all details are printed out and logged. Of course the production version could also log the problem.
Look at this sample code:
Code: Select all
function doSomething()
{
if (!itWorked())
{
if (DEBUG)
throw new Exception(...);
else
return false; // Production level, the client won't even understand the errors. We will log the errors though in more complicated systems.
}
}