Not that im checking for programming errors,
but sometimes in a program a certain function might be buried deep inside the framework and would need to go through multiple levels of function calls. And that it might throw an exception.
What you want to do is to change:
function level2(){
try {
level3();
}
catch (Exception $e) {
throw new Exception($e);
}
}
to:
function level2() {
level3();
}
In other words, instead of translating the exception (and in fact you do not translate it at all since you rethrow an exception of the same type), let it propagate. This is the correct thing to do if you are unable to handle the exception at that level or translate it to a more appropriate type of exception.
Likewise, it is pointless to write:
function level3(){
try {
throw new Exception("..shouting from level 3!!");
}
catch (Exception $e) {
throw new Exception($e);
}
}
You should write:
function level3() {
throw new Exception("..shouting from level 3!!");
}