What is the best practice to handle all the exception in Phalcon?
I have been searching on internet for a while but didn't get any good solution. I would like to know how to handle all the exceptions like database error or file missing error etc.
I think the correct way is to wrap any code block, that is likely to produce any exception, with try and catch. For example, if you are connecting to MongoDB you should wrap that piece of code in a try/catch to make sure you are able to handle connection errors.
try{
//Connect to MongoDB or write any risky code
}
catch(Exception $e){
echo $e.getMessage();
//print stack trace or do some action
}
If you need to handle 404 errors you can do something like this :
Joel Jensen
Loves all things tech
I think the correct way is to wrap any code block, that is likely to produce any exception, with
try and catch. For example, if you are connecting to MongoDB you should wrap that piece of code in a try/catch to make sure you are able to handle connection errors.If you need to handle 404 errors you can do something like this :
The following link may give you more insight : docs.phalconphp.com/en/latest/reference/debug.html