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

(09-22-2015, 07:34 AM)mwhitney Wrote: If the exception isn't caught, none of the code after the try/catch block is likely to be executed, but the code in a finally block will be executed. If the exception is caught, but the catch block prevents the code after the try/catch from being executed (by throwing another exception or returning, for example), the finally block will still be executed (unless you use exit/die in the try/catch block).

Most of the "standard" examples for this are less useful with decent garbage collection, but there are still plenty of cases in which you want to free up any resources used inside the try block which will no longer be needed, regardless of whether the code was executed successfully or threw an exception.

If the finally block uses a return or similar statement, it can essentially suppress an exception thrown in the try/catch blocks, which is certainly something that can't be done by code after the try/catch blocks.

Thanks for the explanation !
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-25-2015, 03:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB