One notable interaction is between the finally block and a return statement. $result = DB::transaction(function () use ($request, $message) wrapper like this: // M圜ontroller. 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. REMEMBER return inside closure is returned in transaction() so if you return redirect()->back() it won't redirect immediately, because the it returned at variable which handle the transaction. When it hits the line throw new Exception, it will stop executing the try block. When an exception is thrown, the code following it will not be executed, and PHP will try to find the matching catch block. One notable interaction is between the finally block and a return statement. In that example, PHP enters the try block and starts executing code. 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. Code within the finally block will always be executed after the. So you could write your code like this, and handle your exception like throw message back into your form via flash or redirect to another page. finally A finally block may also be specified after or instead of catch blocks. In PHP 5.5 and later, a finally block may also be specified after or instead of catch blocks. Laravel Transaction public function transaction(Closure $callback) Here my example code I used to in laravel 5, if you look deep inside DB:transaction() in Illuminate\Database\Connection that the same like you write manual transaction. The code will continue as normal if the exception does not trigger. You could wrapping the transaction over try.catch or even reverse them, 1 In your case finally might work but I dont think the way you use it is a good practice. try: Block of code is represented in which exception can arise.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |