How can be disable exception messages on the production website and keep them in dev?
Example:
try{
//some code
}
catch(Exception $e){
echo $e.getMessage();
}
Edit:
How it done on Zend Framework? (.ini file but what about exception code that should be write?)
Edit 2:
If my example can't work how zend framework disable exception messages in application.ini?
resources.frontController.params.displayExceptions = 0
I'm not sure if we are getting you right.
The other answers tell how whether to throw or not the Exception regarding the environment setting.
The answer is simple: The exceptions should be thrown always, not regarding the environment.
If you need, you may handle them differently, but you should avoid conditional exceptions.
There are many ways, you may set up error handling in your app:
.htaccess
configerror_reporting()
)application.ini
or getting front controller instance in Bootstrap
)The simplest it seems is application.ini
:
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.throwExceptions = 1
resources.frontController.params.displayExceptions = 1
In development section of application.ini
you may use zeros where needed.
I recommend using Log Application resource to handle the exceptions on the production environment.
If you want message printing you could wrap your code inside a function (or static class method) that checks the CONSTANT for values DEVELOPMENT|PRODUCTION
example:
function printMessage($Exception) {
if(DEV_ENVIRONMENT) {
echo $Exception->getMessage();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With