Welcome Guest, Not a member yet? Register   Sign In
Handing errors in my code using Exceptions
#5

(09-21-2015, 07:30 AM)mwhitney Wrote: I don't have a lot of experience using Exceptions in CodeIgniter, but, coming from other environments (primarily other programming languages), the actions I'm willing to take once an exception has occurred are usually pretty limited, because it indicates that the system/application is in an unexpected state. The fact that the "finally" clause was only added in PHP 5.5 just adds to the mess, because it is even less likely that you can sensibly continue execution after an exception without it.

I always use exceptions in my models and libraries. The controllers do the try/catch and return the errors to the ajax calls to be displayed to the user. I usually do that for fatal errors but I also use this technique for failed validation.

I never understand the purpose of "finally". From php.net : "Code within the finally block will always be executed after the try and catch blocks, regardless of whether an exception has been thrown, and before normal execution resumes." If it's always executed, why not just put the code after the try/catch? What difference does it make if the code is in the finally clause instead of after the try/catch?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply


Messages In This Thread
RE: Handing errors in my code using Exceptions - by includebeer - 09-21-2015, 03:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB